Submission #7266143


Source Code Expand

Copy
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
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));

	queue<int>kouho;
	for (int i = 0; i < N; i++)kouho.push(i);
	vector<int>p;

	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;

		p.clear();
		while(kouho.size())
		{
			int a,b;
			a = kouho.front();kouho.pop();
			if(pos[a] == N-1)continue;
			b = A[a][pos[a]];

			if(a > b)swap(a, b);
			if (Match[a][b])
			{
				pos[a]++;
				pos[b]++;
				p.push_back(a);
				p.push_back(b);
				cerr<<a<<" "<<b<<endl;
				flag = true;
			}
			else Match[a][b] = t;
		}
		for(int i=0;i<p.size();i++)kouho.push(p[i]);

		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 500
Code Size 1075 Byte
Status AC
Exec Time 1392 ms
Memory 10240 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 23
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 AC 1392 ms 10240 KB
b09 AC 212 ms 8192 KB
b10 AC 1040 ms 8192 KB
b11 AC 1043 ms 8192 KB
b12 AC 293 ms 2560 KB
b13 AC 245 ms 2176 KB
b14 AC 92 ms 1152 KB
b15 AC 86 ms 896 KB
b16 AC 18 ms 640 KB
b17 AC 31 ms 512 KB
b18 AC 193 ms 1792 KB
b19 AC 156 ms 1408 KB
b20 AC 20 ms 768 KB
b21 AC 38 ms 512 KB
b22 AC 5 ms 384 KB
b23 AC 6 ms 256 KB