Submission #640626

#TimeUsernameProblemLanguageResultExecution timeMemory
640626baokhue232005Zagonetka (COI18_zagonetka)C++14
100 / 100
82 ms372 KiB
/* #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("unroll-loops") */ // lethal option #include<bits/stdc++.h> using namespace std; #define all(flg) flg.begin(), flg.end() #define pb push_back #define fi first #define se second #define eb emplace_back #define ii pair<int, int> #define vi vector<int> #define PI 3.141592653589793238462643383279502884 #define ll long long #define ld long double #define for1(i, ff, gg) for(int i = ff; i <= gg; ++i) #define for2(i, ff, gg) for(int i = ff; i >= gg; --i) const ll mod = 1e9 + 7; const int maxN = 300005; const ll oo = 1e18 + 7; int n, a[maxN]; int x, y, z, k; int posy[101]; bool aw[101][101]; int ray[101]; int cnt[101]; vector<int> vc[101]; void solve(bool suck){ priority_queue<int> pq; for1(i, 1, n){ ray[i] = i; vc[i].clear(); cnt[i] = 0; } // for1(i, 1, n) for1(j, 1, n) if(aw[i][j]){ vc[posy[j]].pb(posy[i]); ++cnt[posy[i]]; } x = n; for1(i, 1, n) if(!cnt[i]) pq.push(i); while(!pq.empty()){ int node = pq.top(); pq.pop(); a[node] = x--; for(int cc : vc[node]){ --cnt[cc]; if(!cnt[cc]) pq.push(cc); } } if(suck) for1(i, 1, n) a[i] = n + 1 - a[i]; for1(i, 1, n) cout << a[i] << " "; cout << endl; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n; for1(i, 1, n){ cin >> x; posy[x] = i; } for1(len, 1, n) for1(l, 1, n){ int r = l + len; if(r > n) continue; for1(i, 1, n){ ray[i] = i; vc[i].clear(); cnt[i] = 0; } for1(i, l, r) ray[i] = 0; int sta = r + 1; for1(i, l, r) for1(j, i + 1, r) if(aw[i][j]){ vc[j].pb(i); ++cnt[i]; } vc[l].pb(r); ++cnt[r]; vector<int> stk; for1(i, l, r) if(!cnt[i]) stk.pb(i); while(!stk.empty()){ int node = stk.back(); stk.pop_back(); ray[node] = --sta; for(int cc : vc[node]){ --cnt[cc]; if(!cnt[cc]) stk.pb(cc); } } x = 0; for1(i, 1, n) if(!ray[i]) x = 1; if(x){ aw[l][r] = 1; continue; } for1(i, 1, n) a[posy[i]] = ray[i]; cout << "query "; for1(i, 1, n) cout << a[i] << " "; cout << endl; cin >> x; if(!x) aw[l][r] = 1; } cout << "end\n"; solve(0); for1(i, 1, n) for1(j, i + 1, n) if(aw[i][j]){ aw[j][i] = 1; aw[i][j] = 0; } solve(1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...