이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)
using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
const int mod = 1000000007;
//Note to self: Check for overflow
#include "xylophone.h"
int a[5005];
int raz[5005];
int p[5005];
pii nadji(int n)
{
int l=1;
int t=0;
fff(i,2,n)
{
t+=raz[i];
if (t<0) t=0,l=i;
if (t==n-1) return {l,i};
}
fff(i,2,n) raz[i]*=-1;
l=1,t=0;
fff(i,2,n)
{
t+=raz[i];
if (t<0) t=0,l=i;
if (t==n-1) return {l,i};
}
return {-1,-1}; //fatally wrong
}
void solve(int n)
{
raz[2]=query(1,2);
fff(i,3,n)
{
raz[i]=query(i-1,i); if (raz[i-1]<0) raz[i]*=-1;
if (abs(raz[i])+abs(raz[i-1])!=query(i-2,i)) raz[i]*=-1;
}
auto [l,r]=nadji(n);
a[l]=1,a[r]=n;
bfff(i,1,l-1)
{
a[i]=a[i+1]-raz[i+1];
}
fff(i,r+1,n)
{
a[i]=a[i-1]+raz[i];
}
fff(i,l+1,r-1)
{
a[i]=a[i-1]+raz[i];
}
fff(i,1,n)
{
answer(i, a[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... |