이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int dif[5001][5001],c[5001],st,ans[5001];
void solve(int n) {
for (int i=1; i<n; ++i) dif[i][i+1]=query(i,i+1);
for (int i=1; i<n-1; ++i) dif[i][i+2]=query(i,i+2);
//first let c[1]>0
c[1]=dif[1][2];
for (int i=2; i<n; ++i) {
c[i]=dif[i][i+1];
if (dif[i-1][i]+dif[i][i+1]==dif[i-1][i+1]) {
if (c[i-1]<0) c[i]=-c[i];
} else {
if (c[i-1]>0) c[i]=-c[i];
}
}
for (int i=1; i<n; ++i) {
int sum=0;
bool have=false;
for (int j=i; j<n; ++j) {
sum+=c[j];
if (abs(sum)==n-1) {
have=true;
st=i;
ans[st]=i;
if (sum==1-n) for (int i=1; i<n; ++i) c[i]=-c[i];
break;
}
}
if (have) break;
}
for (int i=st+1; i<=n; ++i) ans[i]=ans[i-1]+c[i-1];
for (int i=st-1; i>=1; --i) ans[i]=ans[i+1]-c[i];
for (int i=1; i<=n; ++i) answer(i,ans[i]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |