제출 #654545

#제출 시각아이디문제언어결과실행 시간메모리
654545anhduc2701Xylophone (JOI18_xylophone)C++17
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> #include "xylophone.h" using namespace std; typedef long long ll; const ll INF=1e18; const int maxn=1e6+5; const int mod=1e9+7; const int mo=998244353; using pi=pair<ll,ll>; using vi=vector<ll>; using pii=pair<pair<ll,ll>,ll>; #define all(x) x.begin(), x.end() #define len(x) ll(x.size()) #define eb emplace_back #define PI 3.14159265359 #define fi first #define se second #define mp make_pair #define pb push_back #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) int n; int a[5005]; int ok[10005]; int query(int l,int r){ cout<<l<<" "<<r<<endl; int x; cin>>x; return x; } signed main(){ cin>>n; int l=1; int r=n; int pos; while(l<=r){ int mid=(l+r)/2; if(query(mid,n)>=n-1){ pos=mid; l=mid+1; } else{ r=mid-1; } } a[pos]=1; if(pos>1){ a[pos-1]=1+query(pos-1,pos); a[pos+1]=1+query(pos,pos+1); ok[a[pos-1]]=1; ok[a[pos+1]]=1; ok[1]=1; for(int i=pos-2;i>=1;i--){ int hieu=query(i,i+1); if(a[i+1]+hieu>n || ok[a[i+1]+hieu]==1){ a[i]=a[i+1]-hieu; ok[a[i]]=1; continue; } if(a[i+1]-hieu<1 || ok[a[i+1]-hieu]==1){ a[i]=a[i+1]+hieu; ok[a[i]]=1; continue; } int hieumoi=query(i,i+2); int x1=a[i+2]; int y1=a[i+1]; if(y1>x1)swap(x1,y1); if(hieumoi==x1-y1){ a[i]=y1+hieu; ok[a[i]]=1; } if(hieumoi==x1-y1-hieu ){ a[i]=y1+hieu; ok[a[i]]=1; } if(x1-y1+hieu==hieumoi ){ a[i]=y1+hieu; ok[a[i]]=1; } } } if(pos<n){ for(int i=pos+2;i<=n;i++){ int hieu=query(i-1,i); if(a[i-1]+hieu>n || ok[a[i-1]+hieu]==1){ a[i]=a[i-1]-hieu; ok[a[i]]=1; continue; } if(a[i-1]-hieu<1 || ok[a[i-1]-hieu]==1){ a[i]=a[i-1]+hieu; ok[a[i]]=1; continue; } int hieumoi=query(i-2,i); int x1=a[i-2]; int y1=a[i-1]; if(y1>x1)swap(x1,y1); if(hieumoi==x1-y1){ a[i]=y1+hieu; ok[a[i]]=1; } if(hieumoi==x1-y1-hieu ){ a[i]=y1+hieu; ok[a[i]]=1; } if(x1-y1+hieu==hieumoi ){ a[i]=y1+hieu; ok[a[i]]=1; } } } for(int i=1;i<=n;i++){ answer(i,a[i]); } }

컴파일 시 표준 에러 (stderr) 메시지

xylophone.cpp: In function 'int main()':
xylophone.cpp:35:6: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |  int pos;
      |      ^~~
/usr/bin/ld: /tmp/ccLzMPZi.o: in function `query(int, int)':
grader.cpp:(.text+0x0): multiple definition of `query(int, int)'; /tmp/cctDXTdi.o:xylophone.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccLzMPZi.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cctDXTdi.o:xylophone.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccLzMPZi.o: in function `main':
grader.cpp:(.text.startup+0x30): undefined reference to `solve(int)'
collect2: error: ld returned 1 exit status