QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#381678#2160. CardiologySolitaryDream#AC ✓43ms46628kbC++171.4kb2024-04-07 20:11:272024-04-07 20:11:28

Judging History

你现在查看的是最新测评结果

  • [2024-04-07 20:11:28]
  • 评测
  • 测评结果:AC
  • 用时:43ms
  • 内存:46628kb
  • [2024-04-07 20:11:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
#define DOR(i,s,t) for(int i=(s),_t=(t); i>=_t; --i)
typedef long long ll;
const int N=1e6+50;
ll n,m;
ll dist(ll i,ll j) {
    return abs(i*2-n-1)+abs(j*2-m-1);
}
int nxt[N];
vector<int> E[N];
int mx=0;
void dfs(int x,int d) {
    mx=max(mx,d);
    for(auto y: E[x]) {
        dfs(y,d+1);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    ll r=0,u=0,v=0;
    FOR(p,1,m) {
        ll w=(p-1)*n+m;
        vector<pair<ll,ll>> vec;
        if(w>=m && w<=(n+1)*(m-1)) {
            ll i=(w-1)/(m-1);
            ll j=w-i*(m-1);
            vec.push_back({i,j});
        }
        w-=m;
        if(w%(m-1)==0) {
            ll i=w/(m-1);
            if(i>=1 && i<=n) {
                vec.push_back({i,m});
            }
        }
        if(vec.size()==1) {
            auto [i,j]=vec[0];
            if(dist(i,j)<dist(u,v)) {
                r=p;
                u=i,v=j;
            }
        }
    }
    ll p=r;
    FOR(i,1,n) if(i!=u) {
        ll w=(p-1)*n+i;
        ll x=(w-1)/m+1;
        ll y=w-(x-1)*m;
        if(x==u && y==v) {
            nxt[i]=n+1;
        } else {
            nxt[i]=x;
        }
    }
    nxt[u]=n+1;
    FOR(i,1,n) E[nxt[i]].push_back(i);
    dfs(n+1,0);
    cout << p << ' ' << u << ' ' << v << ' ' << mx << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 20ms
memory: 27100kb

input:

6666 966364

output:

473832 3269 483163 2

result:

ok single line: '473832 3269 483163 2'

Test #2:

score: 0
Accepted
time: 21ms
memory: 27312kb

input:

36 906986

output:

12598 1 453493 2

result:

ok single line: '12598 1 453493 2'

Test #3:

score: 0
Accepted
time: 8ms
memory: 33160kb

input:

704877 297616

output:

148803 352426 140980 3

result:

ok single line: '148803 352426 140980 3'

Test #4:

score: 0
Accepted
time: 24ms
memory: 34624kb

input:

1000000 1000000

output:

500000 500000 500000 2

result:

ok single line: '500000 500000 500000 2'

Test #5:

score: 0
Accepted
time: 0ms
memory: 27036kb

input:

2 2

output:

1 1 1 2

result:

ok single line: '1 1 1 2'

Test #6:

score: 0
Accepted
time: 34ms
memory: 46628kb

input:

1000000 2

output:

1 1 1 21

result:

ok single line: '1 1 1 21'

Test #7:

score: 0
Accepted
time: 26ms
memory: 27004kb

input:

2 1000000

output:

250001 1 500001 2

result:

ok single line: '250001 1 500001 2'

Test #8:

score: 0
Accepted
time: 21ms
memory: 35304kb

input:

985391 511611

output:

255806 492696 255806 3

result:

ok single line: '255806 492696 255806 3'

Test #9:

score: 0
Accepted
time: 18ms
memory: 30404kb

input:

435766 614914

output:

304739 215957 307481 2

result:

ok single line: '304739 215957 307481 2'

Test #10:

score: 0
Accepted
time: 8ms
memory: 34004kb

input:

818196 58

output:

29 401921 49 5

result:

ok single line: '29 401921 49 5'

Test #11:

score: 0
Accepted
time: 8ms
memory: 31572kb

input:

401765 19

output:

10 200883 10 6

result:

ok single line: '10 200883 10 6'

Test #12:

score: 0
Accepted
time: 15ms
memory: 27056kb

input:

95 912669

output:

456335 48 456335 2

result:

ok single line: '456335 48 456335 2'

Test #13:

score: 0
Accepted
time: 13ms
memory: 27060kb

input:

81 429950

output:

2655 1 214975 2

result:

ok single line: '2655 1 214975 2'

Test #14:

score: 0
Accepted
time: 21ms
memory: 35372kb

input:

999956 999959

output:

249991 249990 499979 3

result:

ok single line: '249991 249990 499979 3'

Test #15:

score: 0
Accepted
time: 27ms
memory: 34664kb

input:

999935 999946

output:

449976 449971 499976 3

result:

ok single line: '449976 449971 499976 3'

Test #16:

score: 0
Accepted
time: 43ms
memory: 34708kb

input:

999951 999952

output:

1 1 1 2

result:

ok single line: '1 1 1 2'

Test #17:

score: 0
Accepted
time: 9ms
memory: 27852kb

input:

106352 224337

output:

112111 53149 112993 2

result:

ok single line: '112111 53149 112993 2'

Test #18:

score: 0
Accepted
time: 19ms
memory: 33260kb

input:

651870 786333

output:

392936 325744 393775 2

result:

ok single line: '392936 325744 393775 2'

Test #19:

score: 0
Accepted
time: 27ms
memory: 34032kb

input:

838522 972888

output:

486249 419093 486853 2

result:

ok single line: '486249 419093 486853 2'