QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#812015 | #9804. Guess the Polygon | 275307894a# | RE | 1ms | 3880kb | C++14 | 2.4kb | 2024-12-13 10:45:01 | 2024-12-13 10:45:01 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e3+5,M=N*4+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n,A[N],B[N],m;
using LL=__int128;
using frac=pair<LL,LL>;
frac operator +(const frac &A,const frac &B){
int g=__gcd(A.se,B.se);
return frac(B.se/g*A.fi+A.se/g*B.fi,A.se/g*B.se);
}
frac operator -(const frac &A,const frac &B){
return A+frac(-B.fi,B.se);
}
frac operator *(const frac &A,const frac &B){
return frac(A.fi*B.fi,A.se*B.se);
}
frac operator /(const frac &A,const frac &B){
return A*frac(B.se,B.fi);
}
frac query(ll x,ll y){
cout<<"? "<<x<<' '<<y<<endl;
cin>>x>>y;
return frac(x,y);
}
void print(LL x){
if(x>9) print(x/10);
putchar(x%10+48);
}
void Solve(){
cin>>n;m=n;
Me(B,0);
for(int i=1;i<=n;i++){
int x,y;cin>>x>>y;
A[i]=x;B[x]++;
}
sort(A+1,A+n+1);m=unique(A+1,A+n+1)-A-1;
frac La=frac(0,1),ans=frac(0,1);
for(int i=1;i<m;i++){
int px=A[i]*3+1,py=A[i+1]*3-1;
frac w1,w2;
if(B[A[i]]>=2) w1=query(px,3);
else w1=La,px--;
if(i==m-1&&B[A[m]]==1) w2=frac(0,1),py++;
else w2=query(py,3);
frac d=(w2-w1)/frac(py-px,1);
if(px==A[i]*3+1) px--,w1=w1-d;
if(py==A[i+1]*3-1) py++,w2=w2+d;
ans=ans+(w1+w2)*frac(A[i+1]-A[i],2);
La=w2;
}
if(ans.fi<0) ans.fi*=-1,ans.se*=-1;
LL g=__gcd(ans.fi,ans.se);
cout<<"! ";
print(ans.fi/g);
cout<<" ";
print(ans.se/g);
cout<<endl;
}
int main(){
// freopen("1.in","r",stdin);freopen("1.out","w",stdout);
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3880kb
input:
2 4 3 0 1 3 1 1 0 0 4 3 5 3 3 0 0 999 1000 1000 999 1497251 749250
output:
? 2 3 ? 4 3 ! 3 1 ? 2996 3 ! 1999 2
result:
ok correct! (2 test cases)
Test #2:
score: 0
Accepted
time: 1ms
memory: 3872kb
input:
9 4 1 1 1 3 3 0 0 0 2 1 5 6 4 0 0 1 3 1 1 3 0 2 3 5 2 4 0 0 3 0 1 2 1 1 2 3 5 6 4 0 0 3 0 1 2 1 1 4 3 5 6 4 0 0 3 0 1 1 1 2 2 3 5 3 3 1000 0 0 0 0 1000 2999 3 4 0 0 1000 0 1000 1000 0 1000 1000 1 1000 1 5 0 1 1000 1000 1000 0 0 1000 1 0 2998 3 2999 3 1000 1 9 4 1000 3 1 2 1000 3 1000 1 1 2 1 0 0 1 1...
output:
? 2 3 ? 4 3 ! 5 2 ? 2 3 ? 4 3 ! 7 2 ? 2 3 ? 4 3 ! 3 2 ? 2 3 ? 4 3 ! 2 1 ? 2 3 ? 4 3 ! 5 2 ? 1 3 ! 500000 1 ? 1 3 ? 2999 3 ! 1000000 1 ? 1 3 ? 2 3 ? 2999 3 ! 1999999 2 ? 2 3 ? 4 3 ? 5 3 ? 7 3 ? 8 3 ? 10 3 ? 11 3 ! 4003 2
result:
ok correct! (9 test cases)
Test #3:
score: -100
Runtime Error
input:
78 8 951 614 927 614 957 614 957 604 937 614 942 619 951 610 927 604 10 1 10 1 44 3 19 3 10 1 10 1 7 562 260 602 250 582 255 587 260 602 260 562 250 577 260 10 1 10 1 16 3 29 3 10 1 3 454 98 494 68 455 68 39 2 3 526 589 566 559 527 559 39 2 3 854 496 854 466 894 466 119 4 3 797 264 827 254 857 264 8...
output:
? 2782 3 ? 2810 3 ? 2825 3 ? 2852 3 ? 2854 3 ? 2870 3 ! 317 1 ? 1687 3 ? 1730 3 ? 1745 3 ? 1760 3 ? 1805 3 ! 375 1 ? 1364 3 ! 585 1 ? 1580 3 ! 585 1 ? 2563 3 ! 600 1 ? 2480 3 ! 300 1 ? 2158 3 ! 600 1 ? 485 3 ! 400 1 ? 2227 3 ? 2240 3 ? 2242 3 ? 2255 3 ? 2257 3 ? 2375 3 ! 275 1 ? 2797 3 ? 2810 3 ? 28...