QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#167927 | #2731. Cartesian Conquest | lmeowdn | 0 | 1ms | 5304kb | C++14 | 2.2kb | 2023-09-07 18:27:10 | 2023-09-07 18:27:10 |
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-2*n,2*n);
p=dfs(n,m-2*n*x)+x;
} else {
int x=ceil(m-2*n,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: 0
Wrong Answer
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: 3680kb
input:
2 4
output:
1 4
result:
ok single line: '1 4'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
5 4
output:
4 4
result:
ok single line: '4 4'
Test #4:
score: 0
Accepted
time: 1ms
memory: 4040kb
input:
4 6
output:
3 6
result:
ok single line: '3 6'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3696kb
input:
1000 2
output:
250 1000
result:
ok single line: '250 1000'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3964kb
input:
1 1000
output:
500 500
result:
ok single line: '500 500'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3720kb
input:
1000 1000
output:
2 8
result:
ok single line: '2 8'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3948kb
input:
872 976
output:
11 133
result:
ok single line: '11 133'
Test #9:
score: 0
Accepted
time: 1ms
memory: 4356kb
input:
768 992
output:
8 124
result:
ok single line: '8 124'
Test #10:
score: 0
Accepted
time: 1ms
memory: 4096kb
input:
960 896
output:
6 85
result:
ok single line: '6 85'
Test #11:
score: 0
Accepted
time: 1ms
memory: 4352kb
input:
832 992
output:
6 182
result:
ok single line: '6 182'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
26 7
output:
8 8
result:
ok single line: '8 8'
Test #13:
score: 0
Accepted
time: 0ms
memory: 4072kb
input:
38 71
output:
7 30
result:
ok single line: '7 30'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
52 22
output:
5 17
result:
ok single line: '5 17'
Test #15:
score: -5
Wrong Answer
time: 1ms
memory: 4048kb
input:
18 74
output:
8 26
result:
wrong answer 1st lines differ - expected: '6 26', found: '8 26'
Subtask #2:
score: 0
Wrong Answer
Test #20:
score: 8
Accepted
time: 1ms
memory: 3628kb
input:
2 1001
output:
251 1001
result:
ok single line: '251 1001'
Test #21:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
1 1000000
output:
500000 500000
result:
ok single line: '500000 500000'
Test #22:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
1000000 1000000
output:
2 25
result:
ok single line: '2 25'
Test #23:
score: -8
Wrong Answer
time: 1ms
memory: 5304kb
input:
80400 64364
output:
18 616
result:
wrong answer 1st lines differ - expected: '18 622', found: '18 616'
Subtask #3:
score: 0
Wrong Answer
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: 3704kb
input:
99999998 100000000
output:
1562511 100000000
result:
ok single line: '1562511 100000000'
Test #47:
score: -12
Wrong Answer
time: 1ms
memory: 3796kb
input:
67093176 347943
output:
122 166
result:
wrong answer 1st lines differ - expected: '122 245', found: '122 166'