Submission #640763

#TimeUsernameProblemLanguageResultExecution timeMemory
640763uyluluZagonetka (COI18_zagonetka)C++14
18 / 100
116 ms320 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; const int N = 100; bool check = false,adj[N + 1][N + 1],temp[N + 1][N + 1],vis[N + 1]; int deg[N + 1],num[N + 1],pos[N + 1],n; vector<int> topo; void init(int l,int r) { for(int i = 1;i <= n;i++) { deg[i] = 0; vis[i] = false; } for(int i = 1;i <= n;i++) { for(int j = 1;j <= n;j++) temp[i][j] = false; } for(int i = l;i <= r;i++) { for(int j = l;j <= r;j++) { temp[pos[i]][pos[j]] = adj[pos[i]][pos[j]]; if(adj[pos[i]][pos[j]]) { deg[pos[j]]++; } } } check = true; } void dfs(int s) { if(vis[s]) { check = false; return; } topo.push_back(s); vis[s] = true; for(int i = 1;i <= n;i++) { if(temp[s][i]) { dfs(i); } } } int res[N + 1]; int query() { for(int i = 0;i < topo.size();i++) { res[topo[i]] = i + 1; } cout<<"query "; for(int i = 1;i <= n;i++) cout<<res[i]<<" "; cout<<endl; int x; cin>>x; return x; } void small() { priority_queue<int> q; vector<int> kq; for(int i = 1;i <= n;i++) { if(deg[i] == 0) { q.push(i); } } while(!q.empty()) { int s = q.top(); vis[s] = true; q.pop(); kq.push_back(s); for(int i = 1;i <= n;i++) { if(vis[i]) continue; if(adj[s][i]) { vis[i] = true; q.push(i); } } } reverse(kq.begin(),kq.end()); for(int i = 0;i < kq.size();i++) { res[kq[i]] = i + 1; } for(int i = 1;i <= n;i++) cout<<res[i]<<" "; cout<<endl; } void big() { priority_queue<int> q; for(int i = 1;i <= n;i++) { if(deg[i] == 0) { q.push(i); } } vector<int> kq; while(!q.empty()) { int s = q.top(); kq.push_back(s); q.pop(); vis[s] = true; for(int i = 1;i <= n;i++) { if(vis[i]) continue; if(adj[s][i]) { q.push(i); } } } for(int i = 0;i < kq.size();i++) { res[kq[i]] = i + 1; } for(int i = 1;i <= n;i++) cout<<res[i]<<" "; cout<<endl; } int main() { cin>>n; for(int i = 1;i <= n;i++) { cin>>num[i]; pos[num[i]] = i; } for(int len = 1;len <= n - 1;len++) { for(int p = 1;p + len <= n;p++) { adj[pos[p + len]][pos[p]] = true; init(p,p + len); topo.clear(); for(int i = 1;i < p;i++) { topo.push_back(pos[i]); } int cnt = 0; for(int i = p;i <= p + len;i++) { if(deg[pos[i]] == 0) { cnt++; dfs(pos[i]); } } for(int i = p + len + 1;i <= n;i++) { topo.push_back(pos[i]); } adj[pos[p + len]][pos[p]] = false; if(cnt == 0 || !check || !query()) { adj[pos[p]][pos[p + len]] = true; } } } for(int i = 1;i <= n;i++) { for(int j = i + 1;j <= n;j++) { if(adj[i][j]) { adj[j][i] = true; adj[i][j] = false; } else if(adj[j][i]) { adj[i][j] = true; adj[j][i] = false; } } } init(1,n); cout<<"end"<<endl; small(); for(int i = 1;i <= n;i++) { for(int j = i + 1;j <= n;j++) { if(adj[i][j]) { adj[j][i] = true; adj[i][j] = false; } else if(adj[j][i]) { adj[i][j] = true; adj[j][i] = false; } } } init(1,n); big(); exit(0); return 0; }

Compilation message (stderr)

zagonetka.cpp: In function 'int query()':
zagonetka.cpp:49:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(int i = 0;i < topo.size();i++) {
      |                   ~~^~~~~~~~~~~~~
zagonetka.cpp: In function 'void small()':
zagonetka.cpp:82:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int i = 0;i < kq.size();i++) {
      |                   ~~^~~~~~~~~~~
zagonetka.cpp: In function 'void big()':
zagonetka.cpp:109:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |     for(int i = 0;i < kq.size();i++) {
      |                   ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...