QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#167932 | #2731. Cartesian Conquest | lmeowdn | 25 ✓ | 1021ms | 182088kb | C++14 | 2.2kb | 2023-09-07 18:30:35 | 2023-09-07 18:30:35 |
Judging History
answer
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x) {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
return x*w;
}
pii operator + (const pii a,const pii b) {
return pii(min(a.fi,b.fi),max(a.se,b.se));
}
pii operator + (const pii a,const int b) {
return pii(a.fi+b,a.se+b);
}
const int lim=5000;
pii f[lim+5][lim+5];
pii dfs(int n,int m) {
if(n>m) swap(n,m);
if(n==0) return pii(0,0);
if(n==1) return pii(m/2,m/2);
if(n<=lim&&m<=lim) {
if(f[n][m].se) return f[n][m];
}
pii p;
if(m>=4*n) {
if(n%2==1) {
int x=ceil(m-4*n+1,2*n);
p=dfs(n,m-2*n*x)+x;
} else {
int x=ceil(m-4*n+1,2*n);
p=dfs(n,m-2*n*x);
p.fi+=x, p.se+=4*x;
}
} else if(m>=2*n) {
p=dfs(n,m-n*2)+1;
if(n%2==0) p=p+(dfs(n,m-n/2)+1);
} else {
p=pii(n+m,0);
if(n%2==0) p=p+(dfs(n,m-n/2)+1);
if(m%2==0) p=p+(dfs(m,n-m/2)+1);
}
if(n<=lim&&m<=lim) f[n][m]=p;
return p;
}
signed main() {
int n=read(), m=read();
auto [x,y]=dfs(n,m);
printf("%lld %lld\n",x,y);
return 0;
}
詳細信息
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 1ms
memory: 3756kb
input:
2 1
output:
1 1
result:
ok single line: '1 1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
2 4
output:
1 4
result:
ok single line: '1 4'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3696kb
input:
5 4
output:
4 4
result:
ok single line: '4 4'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3740kb
input:
4 6
output:
3 6
result:
ok single line: '3 6'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3740kb
input:
1000 2
output:
250 1000
result:
ok single line: '250 1000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
1 1000
output:
500 500
result:
ok single line: '500 500'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
1000 1000
output:
2 8
result:
ok single line: '2 8'
Test #8:
score: 0
Accepted
time: 1ms
memory: 4128kb
input:
872 976
output:
11 133
result:
ok single line: '11 133'
Test #9:
score: 0
Accepted
time: 1ms
memory: 4092kb
input:
768 992
output:
8 124
result:
ok single line: '8 124'
Test #10:
score: 0
Accepted
time: 1ms
memory: 4336kb
input:
960 896
output:
6 85
result:
ok single line: '6 85'
Test #11:
score: 0
Accepted
time: 1ms
memory: 4088kb
input:
832 992
output:
6 182
result:
ok single line: '6 182'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
26 7
output:
8 8
result:
ok single line: '8 8'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3720kb
input:
38 71
output:
7 30
result:
ok single line: '7 30'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
52 22
output:
5 17
result:
ok single line: '5 17'
Test #15:
score: 0
Accepted
time: 1ms
memory: 4004kb
input:
18 74
output:
6 26
result:
ok single line: '6 26'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3772kb
input:
63 88
output:
12 12
result:
ok single line: '12 12'
Test #17:
score: 0
Accepted
time: 1ms
memory: 3816kb
input:
378 251
output:
11 43
result:
ok single line: '11 43'
Test #18:
score: 0
Accepted
time: 1ms
memory: 4056kb
input:
981 122
output:
12 52
result:
ok single line: '12 52'
Test #19:
score: 0
Accepted
time: 1ms
memory: 4072kb
input:
410 478
output:
10 82
result:
ok single line: '10 82'
Subtask #2:
score: 8
Accepted
Test #20:
score: 8
Accepted
time: 1ms
memory: 3716kb
input:
2 1001
output:
251 1001
result:
ok single line: '251 1001'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
1 1000000
output:
500000 500000
result:
ok single line: '500000 500000'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
1000000 1000000
output:
2 25
result:
ok single line: '2 25'
Test #23:
score: 0
Accepted
time: 2ms
memory: 5500kb
input:
80400 64364
output:
18 622
result:
ok single line: '18 622'
Test #24:
score: 0
Accepted
time: 1ms
memory: 4232kb
input:
5290 4513
output:
15 633
result:
ok single line: '15 633'
Test #25:
score: 0
Accepted
time: 1ms
memory: 3736kb
input:
663518 314601
output:
82 148
result:
ok single line: '82 148'
Test #26:
score: 0
Accepted
time: 1ms
memory: 4640kb
input:
913836 913838
output:
34 913838
result:
ok single line: '34 913838'
Test #27:
score: 0
Accepted
time: 1ms
memory: 3748kb
input:
995579 995578
output:
506 497793
result:
ok single line: '506 497793'
Test #28:
score: 0
Accepted
time: 2ms
memory: 4924kb
input:
997467 997466
output:
36 498737
result:
ok single line: '36 498737'
Test #29:
score: 0
Accepted
time: 2ms
memory: 4984kb
input:
769244 961556
output:
33 384627
result:
ok single line: '33 384627'
Test #30:
score: 0
Accepted
time: 0ms
memory: 27156kb
input:
884224 753344
output:
18 9147
result:
ok single line: '18 9147'
Test #31:
score: 0
Accepted
time: 3ms
memory: 27084kb
input:
893056 501504
output:
16 4043
result:
ok single line: '16 4043'
Test #32:
score: 0
Accepted
time: 1ms
memory: 38796kb
input:
892928 841728
output:
9 3246
result:
ok single line: '9 3246'
Test #33:
score: 0
Accepted
time: 4ms
memory: 36060kb
input:
774144 980992
output:
11 3246
result:
ok single line: '11 3246'
Test #34:
score: 0
Accepted
time: 7ms
memory: 35856kb
input:
741376 956416
output:
12 3242
result:
ok single line: '12 3242'
Test #35:
score: 0
Accepted
time: 8ms
memory: 41096kb
input:
971776 790528
output:
15 3910
result:
ok single line: '15 3910'
Test #36:
score: 0
Accepted
time: 1ms
memory: 36632kb
input:
740096 972288
output:
16 4660
result:
ok single line: '16 4660'
Test #37:
score: 0
Accepted
time: 4ms
memory: 39432kb
input:
996352 771072
output:
12 7065
result:
ok single line: '12 7065'
Test #38:
score: 0
Accepted
time: 19ms
memory: 39316kb
input:
875520 929792
output:
13 5672
result:
ok single line: '13 5672'
Test #39:
score: 0
Accepted
time: 9ms
memory: 42276kb
input:
982016 915456
output:
16 4521
result:
ok single line: '16 4521'
Test #40:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
949669 211072
output:
184 722
result:
ok single line: '184 722'
Test #41:
score: 0
Accepted
time: 2ms
memory: 6416kb
input:
139034 355934
output:
21 363
result:
ok single line: '21 363'
Test #42:
score: 0
Accepted
time: 1ms
memory: 4380kb
input:
576184 726923
output:
30 217
result:
ok single line: '30 217'
Test #43:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
348991 632952
output:
38 223
result:
ok single line: '38 223'
Test #44:
score: 0
Accepted
time: 1ms
memory: 4368kb
input:
465119 181796
output:
26 110
result:
ok single line: '26 110'
Subtask #3:
score: 12
Accepted
Test #45:
score: 12
Accepted
time: 1ms
memory: 3680kb
input:
100000000 2
output:
25000000 100000000
result:
ok single line: '25000000 100000000'
Test #46:
score: 0
Accepted
time: 1ms
memory: 3756kb
input:
99999998 100000000
output:
1562511 100000000
result:
ok single line: '1562511 100000000'
Test #47:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
67093176 347943
output:
122 245
result:
ok single line: '122 245'
Test #48:
score: 0
Accepted
time: 1ms
memory: 3780kb
input:
93205283 93205282
output:
728178 46602645
result:
ok single line: '728178 46602645'
Test #49:
score: 0
Accepted
time: 1ms
memory: 3756kb
input:
98327459 98327458
output:
768195 49163733
result:
ok single line: '768195 49163733'
Test #50:
score: 0
Accepted
time: 1021ms
memory: 179944kb
input:
71169024 93157376
output:
20 67060
result:
ok single line: '20 67060'
Test #51:
score: 0
Accepted
time: 347ms
memory: 182088kb
input:
72652800 61822976
output:
22 53297
result:
ok single line: '22 53297'
Test #52:
score: 0
Accepted
time: 215ms
memory: 169364kb
input:
52917248 50384896
output:
22 38599
result:
ok single line: '22 38599'
Test #53:
score: 0
Accepted
time: 1ms
memory: 18292kb
input:
98797419 98797418
output:
44 49398713
result:
ok single line: '44 49398713'
Test #54:
score: 0
Accepted
time: 1ms
memory: 16556kb
input:
98436250 98436251
output:
44 49218129
result:
ok single line: '44 49218129'
Test #55:
score: 0
Accepted
time: 8ms
memory: 57672kb
input:
95514318 95514316
output:
39 95514318
result:
ok single line: '39 95514318'
Test #56:
score: 0
Accepted
time: 1ms
memory: 3756kb
input:
98501212 98501214
output:
96209 98501214
result:
ok single line: '96209 98501214'
Test #57:
score: 0
Accepted
time: 0ms
memory: 4700kb
input:
97337326 97337324
output:
400 97337326
result:
ok single line: '400 97337326'
Test #58:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
43071676 65675877
output:
151 415
result:
ok single line: '151 415'
Test #59:
score: 0
Accepted
time: 1ms
memory: 3988kb
input:
91366701 3024964
output:
76 121
result:
ok single line: '76 121'
Test #60:
score: 0
Accepted
time: 1ms
memory: 3788kb
input:
2977570 96107
output:
89 223
result:
ok single line: '89 223'
Test #61:
score: 0
Accepted
time: 302ms
memory: 171540kb
input:
96734208 31152128
output:
19 165424
result:
ok single line: '19 165424'
Test #62:
score: 0
Accepted
time: 364ms
memory: 178576kb
input:
66405376 53516288
output:
22 43300
result:
ok single line: '22 43300'
Test #63:
score: 0
Accepted
time: 1ms
memory: 4068kb
input:
75416500 45708415
output:
48 108
result:
ok single line: '48 108'
Test #64:
score: 0
Accepted
time: 14ms
memory: 37720kb
input:
91847572 55451836
output:
30 6342
result:
ok single line: '30 6342'
Test #65:
score: 0
Accepted
time: 1ms
memory: 5300kb
input:
41648757 47581912
output:
57 1093
result:
ok single line: '57 1093'
Test #66:
score: 0
Accepted
time: 2ms
memory: 4892kb
input:
14699477 21130756
output:
34 264
result:
ok single line: '34 264'
Test #67:
score: 0
Accepted
time: 2ms
memory: 4568kb
input:
1524192 39199974
output:
39 435
result:
ok single line: '39 435'
Extra Test:
score: 0
Extra Test Passed