QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#605623#8030. Traveling in the Grid Worlducup-team3519#AC ✓272ms4020kbC++171.4kb2024-10-02 18:13:032024-10-02 18:13:03

Judging History

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

  • [2024-10-02 18:13:03]
  • 评测
  • 测评结果:AC
  • 用时:272ms
  • 内存:4020kb
  • [2024-10-02 18:13:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
typedef pair<int, int> pi;

#define fi first
#define se second
#define V vector
#define pb push_back
#define all1(x) (x).begin() + 1, (x).end()
#define all0(x) (x).begin(), (x).end()

db dis2(LL x, LL y, LL a, LL b) {
    return sqrt(1LL * (x - a) * (x - a) + 1LL * (y - b) * (y - b));
}

// clock_t startTime;
// double getCurrentTime() {
// 	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
// }

mt19937 mrand(chrono::steady_clock().now().time_since_epoch().count());

void solve() {
    cout << fixed << setprecision(12);
    LL n, m; cin >> n >> m;
    if(n > m) swap(n, m);
    // startTime = clock();
    if(__gcd(n, m) == 1) {
        cout << dis2(0, 0, n, m) << "\n";
        return;
    }
    db ans = 1e18;
    for(LL i = 0; i <= n; i++) {
        LL base = (1LL * m * i + n - 1) / n - 1;
        LL x = base;

        while(x >= 0 && (__gcd(i, x) != 1 || __gcd(n - i, m - x) != 1)) {
            x--;
            if(abs(base - x) >= 20) break; 
        }
        if(x >= 0) {
            ans = min(ans, dis2(0, 0, i, x) + dis2(i, x, n, m));
        }
    }
    cout << ans << "\n";
    // cout << getCurrentTime() << endl;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int t; cin >> t;
    while(t--)
    solve();
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3924kb

input:

2
2 2
2 3

output:

3.236067977500
3.605551275464

result:

ok 2 numbers

Test #2:

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

input:

225
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
2 1
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
2 15
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
3 14
3 15
4 1
4 2
4 3
4 4
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
4 15
5 1
5 2
5 3
5 4
5 5
5 6
5 7
5 8
...

output:

1.414213562373
2.236067977500
3.162277660168
4.123105625618
5.099019513593
6.082762530298
7.071067811865
8.062257748299
9.055385138137
10.049875621121
11.045361017187
12.041594578792
13.038404810405
14.035668847618
15.033296378373
2.236067977500
3.236067977500
3.605551275464
4.576491222541
5.3851648...

result:

ok 225 numbers

Test #3:

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

input:

6000
119 101
13 90
96 3
20 99
42 79
57 22
78 138
42 157
179 93
195 12
24 195
62 129
31 166
128 9
46 118
123 113
99 128
187 45
154 84
24 109
143 91
96 100
146 168
115 98
176 36
99 70
198 174
119 33
130 92
184 9
56 196
6 118
136 166
150 118
178 43
105 47
36 4
132 162
171 53
37 180
11 171
77 67
199 51
...

output:

156.083311087381
90.934042030474
96.046886075716
101.000000000000
89.470665583754
61.098281481561
158.518156028175
162.520767903674
201.717624415915
195.368884346967
196.471374493754
143.125818774951
168.869772309907
128.316016147635
126.649125933847
167.026943934205
161.817798773806
192.33824372703...

result:

ok 6000 numbers

Test #4:

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

input:

1400
231 870
23 319
363 117
561 492
841 470
849 886
2 611
921 397
227 916
669 867
874 371
533 16
841 789
782 469
367 291
778 136
694 120
593 89
22 575
6 44
180 871
661 554
397 860
265 547
521 412
809 804
6 554
272 867
240 695
408 900
917 926
47 747
748 750
321 151
291 114
330 31
543 194
387 432
144 ...

output:

900.144988346140
319.828078817355
381.389564951912
746.180273168174
963.421506922074
1227.109204594277
611.003273313654
1002.920734654539
943.708111653174
1095.102734920367
949.482490623182
533.240096016794
1153.170412384917
911.857993330102
468.369512244339
789.797442405113
704.298232312002
599.641...

result:

ok 1400 numbers

Test #5:

score: 0
Accepted
time: 37ms
memory: 3928kb

input:

140
3868 307
1542 8425
7856 1284
8129 8657
773 3877
3073 1195
9579 2327
4058 1337
7080 2717
4183 8192
6189 9162
4094 9648
8098 864
5240 9869
6891 8861
9787 7768
321 97
3839 1384
3271 461
1031 8399
7425 278
6201 2581
2426 9301
3153 6278
3317 9760
34 6044
328 9027
9636 6166
8786 9001
9148 1501
6941 61...

output:

3880.164042923959
8564.951196591841
7960.238187391193
11875.364836500959
3953.309752599712
3297.173638133121
9857.594534165017
4272.579197627588
7583.435171477369
9198.171176924248
11056.489723234961
10480.684137974971
8143.960952755132
11173.842714124805
11225.114787831793
12495.086754400707
335.33...

result:

ok 140 numbers

Test #6:

score: 0
Accepted
time: 25ms
memory: 4016kb

input:

15
92173 34960
85436 79002
67020 16430
77956 88069
10526 52318
63416 18293
13873 21386
41723 31777
89639 91343
48769 44631
41406 14388
52543 19309
89807 68272
22189 65756
16037 54219

output:

98580.239039069085
116364.195953910152
69004.531010651757
117614.993504229729
53366.373307542643
66001.688652639787
25491.589299217889
52446.033768055328
127979.271641934261
66108.558613843634
43834.591135312301
55978.606002650689
112811.183988999954
69398.870718477832
56541.005739197812

result:

ok 15 numbers

Test #7:

score: 0
Accepted
time: 1ms
memory: 3932kb

input:

100
32 1357
71 18212
88 4150
5393 87
3137 50
18767 92
28 6442
29 11081
99 10064
54 17202
87 18903
12158 64
18148 4
7 6246
8293 51
14952 79
15079 87
3525 72
18014 61
22 12994
128 13
78 14983
19850 45
66 14787
8122 25
13318 21
18323 58
805 33
98 12252
14201 86
48 3265
14720 50
88 18800
9595 20
55 1484...

output:

1357.377250435560
18212.138397233863
4150.932907191002
5393.701697350346
3137.398444571553
18767.225500856541
6442.060850380132
11081.037947773666
10064.486921845544
17202.084757377535
18903.200205256253
12158.168447591113
18148.000440819924
6246.003922509175
8293.156817521300
14952.208699720586
150...

result:

ok 100 numbers

Test #8:

score: 0
Accepted
time: 1ms
memory: 3984kb

input:

10
917 58363
44248 132
40874 823
397 22878
58217 320
353 200933
916 230431
775 68654
29128 744
789 24656

output:

58370.203511723339
44248.196889816878
40882.284733121262
22881.444294449597
58217.879461553734
200933.310075756221
230432.820615900971
68658.374150572490
29137.500235950240
24668.620897812671

result:

ok 10 numbers

Test #9:

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

input:

10
29426 81241
88905 209351
47528 40197
3341 95362
21284 82971
222683 93678
31532 19932
38832 87802
49584 60906
52331 10237

output:

86405.957879072201
227446.565650044504
62247.165341082000
95420.507884835737
85657.431067012512
241584.946081083443
37303.507180960878
96005.809345059941
78537.340749480427
53322.881861354792

result:

ok 10 numbers

Test #10:

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

input:

2
49111 368792
490769 13502

output:

372047.617362347839
490954.697874457634

result:

ok 2 numbers

Test #11:

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

input:

1
732421 964572

output:

1211131.563631713856

result:

ok found '1211131.563631714', expected '1211131.563631714', error '0.000000000'

Test #12:

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

input:

1
36078 937705

output:

938398.790018934291

result:

ok found '938398.790018934', expected '938398.790018934', error '0.000000000'

Test #13:

score: 0
Accepted
time: 33ms
memory: 3652kb

input:

1
993066 148246

output:

1004070.195191551233

result:

ok found '1004070.195191551', expected '1004070.195191551', error '0.000000000'

Test #14:

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

input:

1
42547 995544

output:

996452.760117106605

result:

ok found '996452.760117107', expected '996452.760117107', error '0.000000000'

Test #15:

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

input:

1
994185 122012

output:

1001644.019783974974

result:

ok found '1001644.019783975', expected '1001644.019783975', error '0.000000000'

Test #16:

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

input:

1
893299 999105

output:

1340221.587807777338

result:

ok found '1340221.587807777', expected '1340221.587807777', error '0.000000000'

Test #17:

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

input:

1
999507 38171

output:

1000235.606389814522

result:

ok found '1000235.606389815', expected '1000235.606389815', error '0.000000000'

Test #18:

score: 0
Accepted
time: 98ms
memory: 3932kb

input:

1
999994 372210

output:

1067018.408527238062

result:

ok found '1067018.408527238', expected '1067018.408527238', error '0.000000000'

Test #19:

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

input:

1
999945 517082

output:

1125728.118929699762

result:

ok found '1125728.118929700', expected '1125728.118929700', error '0.000000000'

Test #20:

score: 0
Accepted
time: 92ms
memory: 4012kb

input:

1
999495 444185

output:

1093750.688799783122

result:

ok found '1093750.688799783', expected '1093750.688799783', error '0.000000000'

Test #21:

score: 0
Accepted
time: 94ms
memory: 3984kb

input:

1
999994 372210

output:

1067018.408527238062

result:

ok found '1067018.408527238', expected '1067018.408527238', error '0.000000000'

Test #22:

score: 0
Accepted
time: 158ms
memory: 3928kb

input:

1
561402 999944

output:

1146760.746075657895

result:

ok found '1146760.746075658', expected '1146760.746075658', error '0.000000000'

Test #23:

score: 0
Accepted
time: 272ms
memory: 3980kb

input:

1
999990 999999

output:

1414205.784212820930

result:

ok found '1414205.784212821', expected '1414205.784212821', error '0.000000000'

Extra Test:

score: 0
Extra Test Passed