1790C - Premutation - CodeForces Solution


brute force implementation math

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int per[n][n-1];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n-1;j++)
            {
                cin>>per[i][j];
            }
        }
        unordered_map<int,int>mp;
        int first=0;
        for(int i=0;i<n;i++)
        {
            mp[per[i][0]]++;
            if(mp[per[i][0]]>1)
            {
                first=per[i][0];
                break;
            }
        }
        cout<<first<<" ";
        for(int i=0;i<n;i++)
        {
            if(per[i][0]!=first)
            {
                for(int j=0;j<n-1;j++)
                {
                    cout<<per[i][j]<<" ";
                }
                break;
            }
        }
        cout<<endl;
    }
}


Comments

Submit
0 Comments
More Questions

Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble