This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int niz[5005];
int simuliraj(int a, int b, int c){
return max(max(a,b), c) - min(min(a,b), c);
}
void solve(int N){
n = N;
int poz1 = 0;
int l = 1;
int r = n;
/*while(l < r){
int mid = (l + r + 1) / 2;
int pom = query(mid, n);
if(pom == n - 1){
l = mid;
}
else
r = mid - 1;
}
poz1 = l;*/
//cout << poz1 << endl;
for(int i=n; i>=1; i--){
if(query(i,n) == n-1){
poz1 = i;
break;
}
}
niz[poz1] = 1;
if(poz1>1){
niz[poz1 - 1] = 1 + query(poz1 - 1, poz1);
}
niz[poz1 + 1] = 1 + query(poz1, poz1 + 1);
for(int i=poz1 - 2; i >= 1; i--){
int val1 = query(i,i+1);
int prvi = niz[i + 1] - val1;
int drugi = niz[i + 1] + val1;
if(prvi <= 0 || drugi > n){
if(prvi <= 0)niz[i] = drugi;
else niz[i] = prvi;
continue;
}
int val2 = query(i,i+2);
int tmp1 = simuliraj(niz[i + 1], niz[i + 2], prvi);
int tmp2 = simuliraj(niz[i + 1], niz[i + 2], drugi);
if(tmp1 == val2)niz[i] = prvi;
else niz[i] = drugi;
}
for(int i=poz1+2; i<=n; i++){
int val1 = query(i-1,i);
int prvi = niz[i - 1] - val1;
int drugi = niz[i - 1] + val1;
if(prvi <= 0 || drugi > n){
if(prvi <= 0)niz[i] = drugi;
else niz[i] = prvi;
continue;
}
int val2 = query(i-2,i);
int tmp1 = simuliraj(niz[i - 1], niz[i - 2], prvi);
int tmp2 = simuliraj(niz[i - 1], niz[i - 2], drugi);
if(tmp1 == val2)niz[i] = prvi;
else niz[i] = drugi;
}
for(int i=1; i<=n; i++)answer(i, niz[i]);
}
Compilation message (stderr)
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:50:13: warning: unused variable 'tmp2' [-Wunused-variable]
int tmp2 = simuliraj(niz[i + 1], niz[i + 2], drugi);
^~~~
xylophone.cpp:65:13: warning: unused variable 'tmp2' [-Wunused-variable]
int tmp2 = simuliraj(niz[i - 1], niz[i - 2], drugi);
^~~~
xylophone.cpp:15:9: warning: unused variable 'l' [-Wunused-variable]
int l = 1;
^
xylophone.cpp:16:9: warning: unused variable 'r' [-Wunused-variable]
int r = n;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |