Submission #850902

#TimeUsernameProblemLanguageResultExecution timeMemory
850902vjudge1Xylophone (JOI18_xylophone)C++17
0 / 100
0 ms440 KiB
#include <bits/stdc++.h> #define all(v) ((v).begin(),(v).end()) #define ll long long #define F first #define S second const ll mod = 1e9 + 7; const ll mxN = 1e5 + 2; using namespace std; static const int N_MAX = 5000; static const int Q_MAX = 10000; static int N; static int A[N_MAX]; static bool used[N_MAX]; static int query_c; static int answer_c; int query(int s, int t); // if(query_c >= Q_MAX) { // printf("Wrong Answer\n"); // exit(0); // } // query_c++; // if(!(1 <= s && s <= t && t <= N)) { // printf("Wrong Answer\n"); // exit(0); // } // int mx = 0, mn = N + 1; // for(int i = s - 1; i < t; i++) { // if(mx < A[i]) { // mx = A[i]; // } // if(mn > A[i]) { // mn = A[i]; // } // } // return mx - mn; // } void answer(int i, int a); // answer_c++; // if(!(1 <= i && i <= N)) { // printf("Wrong Answer\n"); // exit(0); // } // if(!(1 <= a && a <= N)) { // printf("Wrong Answer\n"); // exit(0); // } // if(used[i - 1]) { // printf("Wrong Answer\n"); // exit(0); // } // if(a != A[i - 1]) { // printf("Wrong Answer\n"); // exit(0); // } // used[i - 1] = true; // } int ans[N_MAX]; int id[N_MAX]; void ass(int x,int i){ answer(i,x); ans[i] = x; id[x] = i; } void solve(int N) { int i = 1,j = N; while(i != j){ if(id[1] && id[N] ) break; if(!id[1] && query(i + 1,j) != N - 1) ass(1,i); else i++; if(!id[N] && query(i,j - 1) != N - 1) ass(N,j); else j--; } int prev = -1; for(int i = id[N] + 1;i <= N;i++){ int x = N - query(id[N],i); if(x != prev) { ass(x,i); prev = x; } } bool bef = 0; for(int i = id[N] + 1;i <= N;i++){ if(ans[i]) bef = 0; else if(!bef){ int x = ans[i - 1] + query(i - 1,i); ass(x,i); bef = 1; }else if(bef){ int x = ans[i - 1] - query(i - 1,i); ass(x,i); } } prev = -1; for(int i = id[1] - 1;i;i--){ int x = 1 + query(i,id[1]); if(x != prev){ ass(x,i); prev = x; } } bef = 0; for(int i = id[1] - 1;i;i--){ if(ans[i]) bef = 0; else if(!bef){ int x = ans[i + 1] - query(i,i + 1); ass(x, i); bef = 1; }else if(bef){ int x = ans[i + 1] + query(i, i + 1); ass(x, i); } } prev = -1; for(int i = id[N] - 1;i > id[1];i--){ int x = N - query(i,id[N]); if(x != prev){ ass(x,i); prev = x; } } bef = 0; for(int i = id[N] - 1;i > id[1];i--){ if(ans[i]) bef = 0; else if(!bef){ int x = ans[i + 1] + query(i,i + 1); ass(x, i); bef = 1; }else if(bef){ int x = ans[i + 1] - query(i, i + 1); ass(x, i); } } // for(int i = 1;i <= N;i++) cout<<ans[i]<<' '; // cout<<'\n'; } // // int main() { // query_c = 0; // answer_c = 0; // if(scanf("%d", &N) != 1) { // fprintf(stderr, "Error while reading input\n"); // exit(1); // } // for(int i = 0; i < N; i++) { // if(scanf("%d", A + i) != 1) { // fprintf(stderr, "Error while reading input\n"); // exit(1); // } // used[i] = false; // } // solve(N); // if(!(answer_c == N)) { // printf("Wrong Answer\n"); // exit(0); // } // printf("Accepted : %d\n", query_c); // }

Compilation message (stderr)

xylophone.cpp:15:12: warning: 'answer_c' defined but not used [-Wunused-variable]
   15 | static int answer_c;
      |            ^~~~~~~~
xylophone.cpp:14:12: warning: 'query_c' defined but not used [-Wunused-variable]
   14 | static int query_c;
      |            ^~~~~~~
xylophone.cpp:13:13: warning: 'used' defined but not used [-Wunused-variable]
   13 | static bool used[N_MAX];
      |             ^~~~
xylophone.cpp:12:12: warning: 'A' defined but not used [-Wunused-variable]
   12 | static int A[N_MAX];
      |            ^
xylophone.cpp:11:12: warning: 'N' defined but not used [-Wunused-variable]
   11 | static int N;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...