Task: | Monotonic |
Sender: | Wave of Technology |
Submission time: | 2018-05-26 15:31:26 +0300 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.02 s | details |
#3 | ACCEPTED | 0.02 s | details |
#4 | ACCEPTED | 0.06 s | details |
#5 | ACCEPTED | 0.01 s | details |
#6 | ACCEPTED | 0.01 s | details |
#7 | ACCEPTED | 0.03 s | details |
#8 | ACCEPTED | 0.02 s | details |
#9 | ACCEPTED | 0.02 s | details |
#10 | ACCEPTED | 0.03 s | details |
Code
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> PLL; const ll INF = 1000000000000000LL; ll n; template<typename T> void print_vector(vector<T> & v) { for (auto x : v) { cout << x << " "; } } const ll MAXK = 1000; const ll TRY = 1000; ll solve() { ll n, m; cin >> n >> m; vector<PLL> pr(m); for (int i=0; i<m; i++) { cin >> pr[i].first; cin >> pr[i].second; pr[i].first--; pr[i].second--; } ll maxk = 0; for (int ii=0; ii<TRY; ii++) { vector<ll> x (n); for (int i=0; i<n; i++) { x[i] = rand(); } ll k = 0; while (k < MAXK) { k++; for (auto p : pr) { if (x[p.first] > x[p.second]) { swap(x[p.first], x[p.second]); } } bool sorted = true; for (int i=0; i<n-1; i++) { sorted &= (x[i] <= x[i+1]); } if (sorted) { break; } } maxk = max(k, maxk); if (maxk == MAXK) { break; } } if (maxk == MAXK) { return -1; } else { return maxk; } } int main() { cin.tie(NULL); std::ios::sync_with_stdio(false); ll t; cin >> t; for (int i=0; i<t; i++) { cout << solve() << endl; } return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
3 4 4 1 2 3 4 1 2 ... |
correct output |
---|
-1 3 1 |
user output |
---|
-1 3 1 |
Test 2
Verdict: ACCEPTED
input |
---|
10 15 200 1 14 2 6 3 14 ... |
correct output |
---|
-1 -1 -1 -1 -1 ... |
user output |
---|
-1 -1 -1 -1 -1 ... |
Test 3
Verdict: ACCEPTED
input |
---|
10 15 350 1 14 2 6 3 14 ... |
correct output |
---|
3 -1 2 -1 1 ... |
user output |
---|
3 -1 2 -1 1 ... |
Test 4
Verdict: ACCEPTED
input |
---|
10 15 1500 1 14 2 6 3 14 ... |
correct output |
---|
1 1 1 1 1 ... |
user output |
---|
1 1 1 1 1 ... |
Test 5
Verdict: ACCEPTED
input |
---|
10 15 100 4 10 3 9 6 15 ... |
correct output |
---|
-1 -1 -1 -1 -1 ... |
user output |
---|
-1 -1 -1 -1 -1 ... |
Test 6
Verdict: ACCEPTED
input |
---|
10 15 200 4 5 2 12 7 8 ... |
correct output |
---|
-1 -1 -1 -1 -1 ... |
user output |
---|
-1 -1 -1 -1 -1 ... |
Test 7
Verdict: ACCEPTED
input |
---|
10 15 300 5 10 6 12 12 13 ... |
correct output |
---|
-1 -1 2 2 -1 ... |
user output |
---|
-1 -1 2 2 -1 ... |
Test 8
Verdict: ACCEPTED
input |
---|
10 15 400 10 13 2 14 8 13 ... |
correct output |
---|
-1 1 1 -1 1 ... |
user output |
---|
-1 1 1 -1 1 ... |
Test 9
Verdict: ACCEPTED
input |
---|
10 15 14 14 15 11 12 1 2 ... |
correct output |
---|
8 7 4 4 3 ... |
user output |
---|
8 7 4 4 3 ... |
Test 10
Verdict: ACCEPTED
input |
---|
10 15 14 1 2 2 3 3 4 ... |
correct output |
---|
14 7 5 4 3 ... |
user output |
---|
14 7 5 4 3 ... |