QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#376860 | #2160. Cardiology | installb# | AC ✓ | 6ms | 3648kb | C++20 | 3.8kb | 2024-04-04 17:44:42 | 2024-04-04 17:44:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
int n,m,a[55][55];
int cnt[55][55],mx[55][55];
void solve(){
cin >> n >> m;
for(int p = 1;p <= m;p ++){
memset(cnt,0,sizeof(cnt));
memset(mx,0,sizeof(mx));
set <int> st;
for(int x = 1;x <= n * m;x ++){
int tot = 0;
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= m;j ++){
a[i][j] = ++ tot;
}
}
int posx,posy;
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= m;j ++){
if(a[i][j] == x) posx = i,posy = j;
}
}
vector <pair <int,int> > G;
G.push_back({posx,posy});
int fl = 0;
for(int ti = 1;ti <= 1000;ti ++){
vector <int> lis,H;
for(int j = 1;j <= m;j ++){
if(j == posy) continue;
for(int i = 1;i <= n;i ++) lis.push_back(a[i][j]);
}
for(int i = 0;i < (p - 1) * n;i ++) H.push_back(lis[i]);
for(int i = 1;i <= n;i ++) H.push_back(a[i][posy]);
for(int i = (p - 1) * n;i < lis.size();i ++) H.push_back(lis[i]);
int cur = 0;
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= m;j ++){
a[i][j] = H[cur ++];
if(a[i][j] == x) posx = i,posy = j;
}
}
if(make_pair(posx,posy) == G.back()){
fl = 1; break;
}
G.push_back({posx,posy});
}
if(fl){
// cout << "P = " << p << ", Gsize = " << G.size() << '\n';
// for(auto [x,y] : G) cout << x << ',' << y << ' ';
// cout << '\n';
auto [x,y] = G.back();
cnt[x][y] ++;
mx[x][y] = max(mx[x][y],(int)(G.size()) - 1);
cout << (G.size() - 1) << ',';
}
}
cout << '\n';
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= m;j ++){
if(cnt[i][j] == n * m){
cout << i << ',' << j << ' ' << mx[i][j] << " P = " << p << '\n';
}
}
}
}
}
*/
#define int long long
struct node{
int dis,p,x,y;
bool operator < (const node &nd)const{
if(dis == nd.dis) return p < nd.p;
return dis < nd.dis;
}
};
inline int calcc(int xa,int ya,int xb,int yb){ return abs(xa - xb) + abs(ya - yb); }
int calcd(int n,int m,int x,int y){
return min({calcc(x,y,(n + 1) / 2,(m + 1) / 2),calcc(x,y,(n + 1) / 2,m / 2 + 1),calcc(x,y,n / 2 + 1,(m + 1) / 2),calcc(x,y,n / 2 + 1,m / 2 + 1)});
}
int runc(int sx,int sy,int tx,int ty,int p,int n,int m){
for(int ti = 1;;ti ++){
if(sx == tx && sy == ty) return ti - 1;
int pos = (p - 1) * n + (sx - 1);
sx = pos / m + 1; sy = pos % m + 1;
}
}
void solve(){
int n,m; cin >> n >> m;
node ans = min((node){calcd(n,m,1,1),1,1,1},(node){calcd(n,m,n,m),m,n,m});
for(int p = 2;p < m;p ++){
int val = (p - 1) * n;
int x = val / (m - 1) + 1,y = val % (m - 1) + 1;
if(y != 1){
ans = min(ans,{calcd(n,m,x,y),p,x,y});
}
}
int stp = runc(1,1,ans.x,ans.y,ans.p,n,m);
stp = max(stp,runc(n,m,ans.x,ans.y,ans.p,n,m));
stp = max(stp,runc(1,m,ans.x,ans.y,ans.p,n,m));
stp = max(stp,runc(n,1,ans.x,ans.y,ans.p,n,m));
cout << ans.p << ' ' << ans.x << ' ' << ans.y << ' ' << stp << '\n';
}
signed main(){
ios::sync_with_stdio(false);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 3624kb
input:
6666 966364
output:
473832 3269 483163 2
result:
ok single line: '473832 3269 483163 2'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3648kb
input:
36 906986
output:
12598 1 453493 2
result:
ok single line: '12598 1 453493 2'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3612kb
input:
704877 297616
output:
148803 352426 140980 3
result:
ok single line: '148803 352426 140980 3'
Test #4:
score: 0
Accepted
time: 6ms
memory: 3588kb
input:
1000000 1000000
output:
500000 500000 500000 2
result:
ok single line: '500000 500000 500000 2'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
2 2
output:
1 1 1 2
result:
ok single line: '1 1 1 2'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
1000000 2
output:
1 1 1 21
result:
ok single line: '1 1 1 21'
Test #7:
score: 0
Accepted
time: 6ms
memory: 3600kb
input:
2 1000000
output:
250001 1 500001 2
result:
ok single line: '250001 1 500001 2'
Test #8:
score: 0
Accepted
time: 3ms
memory: 3608kb
input:
985391 511611
output:
255806 492696 255806 3
result:
ok single line: '255806 492696 255806 3'
Test #9:
score: 0
Accepted
time: 4ms
memory: 3620kb
input:
435766 614914
output:
304739 215957 307481 2
result:
ok single line: '304739 215957 307481 2'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
818196 58
output:
29 401921 49 5
result:
ok single line: '29 401921 49 5'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
401765 19
output:
10 200883 10 6
result:
ok single line: '10 200883 10 6'
Test #12:
score: 0
Accepted
time: 5ms
memory: 3604kb
input:
95 912669
output:
456335 48 456335 2
result:
ok single line: '456335 48 456335 2'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3604kb
input:
81 429950
output:
2655 1 214975 2
result:
ok single line: '2655 1 214975 2'
Test #14:
score: 0
Accepted
time: 6ms
memory: 3572kb
input:
999956 999959
output:
249991 249990 499979 3
result:
ok single line: '249991 249990 499979 3'
Test #15:
score: 0
Accepted
time: 5ms
memory: 3620kb
input:
999935 999946
output:
449976 449971 499976 3
result:
ok single line: '449976 449971 499976 3'
Test #16:
score: 0
Accepted
time: 3ms
memory: 3648kb
input:
999951 999952
output:
1 1 1 2
result:
ok single line: '1 1 1 2'
Test #17:
score: 0
Accepted
time: 2ms
memory: 3624kb
input:
106352 224337
output:
112111 53149 112993 2
result:
ok single line: '112111 53149 112993 2'
Test #18:
score: 0
Accepted
time: 4ms
memory: 3644kb
input:
651870 786333
output:
392936 325744 393775 2
result:
ok single line: '392936 325744 393775 2'
Test #19:
score: 0
Accepted
time: 5ms
memory: 3644kb
input:
838522 972888
output:
486249 419093 486853 2
result:
ok single line: '486249 419093 486853 2'