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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
static int D[5111];
static int D2[5111];
static int change[5111];
int ask(int l, int r)
{
l++; r++;
return query(l,r);
}
void out(vector<int> &v)
{
for(int i=0;i<v.size();i++)
{
answer(i+1,v[i]+1);
}
}
bool valid(vector<int> &v)
{
bool ok=0;
for(int i=0;i<v.size();i++)
{
if(v[i]==0) ok=1;
if(!ok&&v[i]==int(v.size())-1) return false;
if(v[i]<0||v[i]>=int(v.size())) return false;
}
return true;
}
void solve(int N)
{
vector<int> A(N);
for(int i=0;i+1<N;i++)
{
D[i] = ask(i,i+1);
if(i+2<N) D2[i] = ask(i,i+2);
}
for(int i=2;i<N;i++)
{
if(D[i-2]+D[i-1]==D2[i-2])
{
change[i] = 0;
}
else
{
change[i] = 1;
}
}
for(int i=0;i<N;i++)
{
for(int j=0;j<2;j++)
{
vi V(N);
V[0] = i; int cur = j;
for(int k=1;k<N;k++)
{
if(cur) V[k]=V[k-1]+D[k-1];
else V[k]=V[k-1]-D[k-1];
if(k+1<N&&change[k+1]) cur^=1;
}
if(valid(V)) {out(V); return ;}
}
}
}
Compilation message (stderr)
xylophone.cpp: In function 'void out(std::vector<int>&)':
xylophone.cpp:32:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();i++)
~^~~~~~~~~
xylophone.cpp: In function 'bool valid(std::vector<int>&)':
xylophone.cpp:41:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();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... |