Submission #484005

#TimeUsernameProblemLanguageResultExecution timeMemory
484005MilosMilutinovicXylophone (JOI18_xylophone)C++14
100 / 100
362 ms640 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head const int N=5010; int n,a[N],x[N],y[N]; VI ans; //int query(int l,int r) { // int mn=(1<<29),mx=0; // rep(i,l,r+1) mn=min(mn,a[i]),mx=max(mx,a[i]); // return mx-mn; //} int check(int r) { rep(i,1,n+1) { VI v={i}; rep(j,1,n) { v.pb(v.back()+x[j]*r); if (j!=n-1) if (y[j]!=x[j]+x[j+1]) r=(r==-1?1:-1); } int px,py; rep(j,0,n) if (v[j]==1) px=j; rep(j,0,n) if (v[j]==n) py=j; if (*min_element(all(v))==1&&*max_element(all(v))==n) { vector<bool> was(n+1,false); rep(j,0,n) was[v[j]]=true; bool ok=true; rep(j,1,n+1) if (!was[j]) ok=false; if (ok&&px<py) { ans=v; return i; } } } return -1; } void solve(int N) { n=N; rep(i,1,n) x[i]=query(i,i+1); rep(i,1,n-1) y[i]=query(i,i+2); check(-1); check(1); assert(SZ(ans)>0); // rep(i,0,n) printf("%d ",ans[i]); rep(i,0,n) answer(i+1,ans[i]); } //int main() { // scanf("%d",&n); // rep(i,1,n+1) scanf("%d",a+i); // solve(n); //} /* 5 2 1 5 3 4 */

Compilation message (stderr)

xylophone.cpp: In function 'int check(int)':
xylophone.cpp:46:14: warning: 'py' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |    if (ok&&px<py) {
      |            ~~^~~
xylophone.cpp:46:14: warning: 'px' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...