Submission #7261333


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vvl order(n,vl(n-1));
	FOR(i,0,n) FOR(j,0,n-1) {
		ll x; cin >> x;
		order[i][j] = x-1;
	}
	vl ptr(n);
	
	ll res = 0;
	while (true) {
		bool change = false;
		vb mark(n);
		FOR(i,0,n) if (ptr[i] < n-1 && !mark[i]) {
			ll j = order[i][ptr[i]];
			if (ptr[j] < n-1 && !mark[j] && order[j][ptr[j]] == i) {
				ptr[i]++, ptr[j]++;
				mark[i] = mark[j] = true;
				change = true;
			}
		}
		if (!change) break;
		res++;
	}
	
	if (ptr != vl(n,n-1)) res = -1;
	cout << res << endl;
}

Submission Info

Submission Time
Task E - League
User pwild
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1183 Byte
Status TLE
Exec Time 2104 ms
Memory 8064 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 2104 ms 8064 KB
b09 AC 68 ms 8064 KB
b10 AC 94 ms 8064 KB
b11 AC 92 ms 8064 KB
b12 AC 25 ms 2560 KB
b13 AC 21 ms 2176 KB
b14 AC 11 ms 1152 KB
b15 AC 10 ms 896 KB
b16 AC 5 ms 640 KB
b17 AC 6 ms 512 KB
b18 AC 21 ms 1792 KB
b19 AC 17 ms 1536 KB
b20 AC 6 ms 768 KB
b21 AC 5 ms 512 KB
b22 AC 2 ms 384 KB
b23 AC 2 ms 256 KB