Submission #996038

#TimeUsernameProblemLanguageResultExecution timeMemory
996038TozzyyyyXylophone (JOI18_xylophone)C++17
100 / 100
86 ms600 KiB
#include<bits/stdc++.h> #include "xylophone.h" using namespace std; void solve(int n) { vector<int> a(n+2); vector<int> b(n+1) , c(n+1); for(int i = 1 ; i < n ; i++){ b[i] = query(i , i+1); } for(int i = 2 ; i < n ; i++){ c[i] = query(i-1 , i+1); } for(int i = 1 ; i <= n ; i++){ a[i] = 1; a[i+1] = 1 + b[i]; a[i-1] = b[i-1] + 1; for(int j = i + 2 ; j <= n ; j++){ if(a[j-1] > a[j-2]){ if(b[j-2] + b[j-1] == c[j-1]) a[j] = a[j-1] + b[j-1]; else a[j] = a[j-1] - b[j-1]; }else{ if(b[j-2] + b[j-1] == c[j-1]) a[j] = a[j-1] - b[j-1]; else a[j] = a[j-1] + b[j-1]; } } for(int j = i - 2 ; j >= 1 ; j--){ if(a[j+1] > a[j+2]){ if(b[j+1] + b[j] == c[j+1]) a[j] = a[j+1] + b[j]; else a[j] = a[j+1] - b[j]; }else{ if(b[j+1] + b[j] == c[j+1]) a[j] = a[j+1] - b[j]; else a[j] = a[j+1] + b[j]; } } vector<int> cnt(n+1); int C = 0; for(int i = 1 ; i <= n ; i ++){ if(a[i] < 1 or a[i] > n){ C=1; break; } if(cnt[a[i]] == 1){ C=1; break; } cnt[a[i]]=1; } if(C==0){ for(int i = 1 ; i <= n ; i++) answer(i , a[i]); break; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...