Submission #1116817

#TimeUsernameProblemLanguageResultExecution timeMemory
1116817mmkXylophone (JOI18_xylophone)C++17
0 / 100
4 ms336 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; int a[5000]; map<pair<int,int>,int> marc; int q(int ini, int fim) { if(!marc[{ini,fim}]) return marc[{ini,fim}] = query(ini,fim); else return marc[{ini,fim}]; } void solve(int N) { a[1] = 0; a[2] = a[1] + q(1,2); int menor = 2*N, maior = -2*N; int minPos = 0, maxPos = 0; for(int i = 2; i < N; i++) { int d12 = q(i-1,i); int d23 = q(i,i+1); int d13 = q(i-1,i+1); int sign = (a[i] - a[i-1])/d12; if(d13 == d12 + d23) a[i+1] = a[i-1] + sign*(d13); else a[i+1] = a[i] - sign*(d23); } for(int i = 1; i <= N; i++) { if(a[i] < menor) { menor = a[i]; minPos = i; } if(a[i] > maior) { maior = a[i]; maxPos = i; } } int dif = 1 - menor; if(minPos < maxPos) { for(int i = 1; i <= N; i++) answer(i,a[i] + dif); } else { for(int i = 1; i <= N; i++) answer(N - i + 1,a[i] + dif); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...