Submission #7263051


Source Code Expand

Copy
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main() {
	int N;cin>>N;
	vector<vector<int>>A(N, vector<int>(N));
	for(int i=0;i<N;i++)for(int j=0;j<N-1;j++)
	{
		cin>>A[i][j];
		A[i][j]--;
	}
	vector<int>pos(N);

	vector<vector<int>>Match(N, vector<int>(N));

	int t = 1;
	while (1)
	{
		bool flag = true;
		for(int i=0;i<N;i++)if(pos[i] != N-1)flag = false;
		if(flag)break;

		for (int i = 0; i < N; i++)
		{
			if(pos[i] == N-1)continue;

			int a,b;
			a = i;
			b = A[i][pos[i]];

			if(a > b)swap(a, b);
			if (Match[a][b] == t)
			{
				pos[a]++;
				pos[b]++;

				flag = true;
			}
			else Match[a][b] = t;
		}

		if (flag == false)
		{
			cout<<-1<<endl;
			return 0;
		}

		t++;
	}

	cout<<t-1<<endl;

	return 0;
}

Submission Info

Submission Time
Task E - League
User kurenai3110
Language C++14 (GCC 5.4.1)
Score 0
Code Size 837 Byte
Status TLE
Exec Time 2103 ms
Memory 10240 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 22
TLE × 1
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 TLE 2103 ms 10240 KB
b09 AC 213 ms 8192 KB
b10 AC 258 ms 8192 KB
b11 AC 252 ms 8192 KB
b12 AC 64 ms 2560 KB
b13 AC 55 ms 2176 KB
b14 AC 27 ms 1152 KB
b15 AC 21 ms 896 KB
b16 AC 12 ms 640 KB
b17 AC 9 ms 512 KB
b18 AC 48 ms 1792 KB
b19 AC 38 ms 1408 KB
b20 AC 14 ms 768 KB
b21 AC 10 ms 512 KB
b22 AC 5 ms 384 KB
b23 AC 2 ms 256 KB