QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#351585#6140. 矩阵游戏hos_lyric75 891ms7788kbC++143.2kb2024-03-12 06:46:092024-03-12 06:46:11

Judging History

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

  • [2024-03-12 06:46:11]
  • 评测
  • 测评结果:75
  • 用时:891ms
  • 内存:7788kb
  • [2024-03-12 06:46:09]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


/*
  a[x][y] = (-1)^(x+y) (p[x] - q[y]) + c[x][y]
  c: c[*][0] = c[0][*] = 0, others determined by B
*/

#define MAX [310][310]

constexpr Int L = 1'000'000;

int M, N;
Int B MAX;

Int a MAX, c MAX, f MAX, g MAX;

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d%d", &M, &N);
    for (int x = 1; x < M; ++x) for (int y = 1; y < N; ++y) {
      scanf("%lld", &B[x][y]);
    }
    
    for (int x = 0; x < M; ++x) for (int y = 0; y < N; ++y) {
      c[x][y] = (x == 0 || y == 0) ? 0 : (B[x][y] - c[x-1][y-1] - c[x-1][y] - c[x][y-1]);
    }
// for(int x=0;x<M;++x){cerr<<"c["<<x<<"] = ";pv(c[x],c[x]+N);}
    for (int x = 0; x < M; ++x) for (int y = 0; y < N; ++y) {
      if ((x + y) & 1) {
        // 0 <= - p[x] + q[y] + c[x][y] <= L
        g[x][y] = c[x][y];
        f[x][y] = L - c[x][y];
      } else {
        // 0 <= + p[x] - q[y] + c[x][y] <= L
        f[x][y] = c[x][y];
        g[x][y] = L - c[x][y];
      }
    }
    
    vector<Int> dist(M + N, 0);
    for (int h = 0; h < M + N; ++h) {
      for (int x = 0; x < M; ++x) for (int y = 0; y < N; ++y) {
        chmin(dist[M + y], dist[x] + f[x][y]);
        chmin(dist[x], dist[M + y] + g[x][y]);
      }
    }
    bool ok = true;
    for (int x = 0; x < M; ++x) for (int y = 0; y < N; ++y) {
      ok = ok && (dist[M + y] <= dist[x] + f[x][y]);
      ok = ok && (dist[x] <= dist[M + y] + g[x][y]);
    }
    
    if (ok) {
      for (int x = 0; x < M; ++x) for (int y = 0; y < N; ++y) {
        a[x][y] = ((x + y) & 1 ? -1 : +1) * (dist[x] - dist[M + y]) + c[x][y];
      }
      puts("YES");
      for (int x = 0; x < M; ++x) {
        for (int y = 0; y < N; ++y) {
          if (y) printf(" ");
          printf("%lld", a[x][y]);
        }
        puts("");
      }
    } else {
      puts("NO");
    }
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

详细

Test #1:

score: 5
Accepted
time: 1ms
memory: 5856kb

input:

10
3 3
9 21
22 16
3 3
28 30
13 4
3 3
17 10
5 30
3 3
30 27
30 25
3 3
22 19
28 12
3 3
30 27
21 28
3 3
4 25
11 5
3 3
12 24
24 30
3 3
5 4
27 8
3 3
20 29
17 18

output:

YES
0 0 18
6 3 0
0 13 0
YES
15 0 26
9 4 0
0 0 0
YES
12 0 0
0 5 5
0 0 20
YES
0 0 2
5 25 0
0 0 0
YES
0 0 13
16 6 0
0 6 0
YES
9 0 0
0 21 6
0 0 1
YES
0 0 25
4 0 0
2 5 0
YES
0 0 6
0 12 6
0 12 0
YES
0 0 4
5 0 0
14 8 0
YES
3 0 11
0 17 1
0 0 0

result:

ok you are right!!

Test #2:

score: 5
Accepted
time: 1ms
memory: 5800kb

input:

10
3 3
5 18
16 21
3 3
28 30
27 5
3 3
30 12
9 11
3 3
28 20
30 13
3 3
22 27
28 5
3 3
30 29
30 23
3 3
17 13
22 13
3 3
29 24
29 25
3 3
23 12
3 2
3 3
20 30
23 30

output:

YES
0 0 8
0 5 5
0 11 0
YES
1 0 25
22 5 0
0 0 0
YES
21 0 1
0 9 2
0 0 0
YES
0 0 9
17 11 0
0 2 0
YES
0 0 27
22 0 0
1 5 0
YES
0 0 6
7 23 0
0 0 0
YES
0 0 5
9 8 0
0 5 0
YES
0 0 0
5 24 0
0 0 1
YES
20 0 10
1 2 0
0 0 0
YES
0 0 3
0 20 7
0 3 0

result:

ok you are right!!

Test #3:

score: 5
Accepted
time: 1ms
memory: 5924kb

input:

10
3 3
17 22
17 27
3 3
30 24
30 30
3 3
11 16
10 15
3 3
29 18
19 27
3 3
12 2
25 26
3 3
27 28
29 30
3 3
14 11
8 16
3 3
29 27
26 15
3 3
1 21
25 12
3 3
30 28
21 27

output:

YES
0 0 0
0 17 5
0 0 5
YES
0 0 0
6 24 0
0 0 6
YES
1 0 1
0 10 5
0 0 0
YES
10 0 0
1 18 0
0 0 9
YES
0 0 0
10 2 0
0 13 11
YES
0 0 0
0 27 1
0 2 0
YES
6 0 0
0 8 3
0 0 5
YES
3 0 12
11 15 0
0 0 0
YES
0 0 21
1 0 0
12 12 0
YES
9 0 1
0 21 6
0 0 0

result:

ok you are right!!

Test #4:

score: 5
Accepted
time: 0ms
memory: 4100kb

input:

10
3 3
6 30
30 11
3 3
29 28
11 25
3 3
26 26
15 22
3 3
23 30
29 6
3 3
16 8
13 20
3 3
26 30
29 28
3 3
3 24
4 2
3 3
29 30
24 29
3 3
15 12
7 4
3 3
30 26
25 30

output:

YES
0 0 30
6 0 0
13 11 0
YES
18 0 3
0 11 14
0 0 0
YES
11 0 4
0 15 7
0 0 0
YES
0 0 30
23 0 0
0 6 0
YES
3 0 0
5 8 0
0 0 12
YES
0 0 5
1 25 0
0 3 0
YES
0 0 23
2 1 0
0 1 0
YES
5 0 1
0 24 5
0 0 0
YES
8 0 8
3 4 0
0 0 0
YES
5 0 0
0 25 1
0 0 4

result:

ok you are right!!

Test #5:

score: 5
Accepted
time: 0ms
memory: 3920kb

input:

10
10 2
240
8788
3257
6676
9748
4941
1268
2569
7827
10 2
9542
9328
8351
9362
9771
9183
8527
8640
7370
10 2
3144
7704
2054
9901
3567
120
2273
2407
4202
10 2
7337
9013
9119
9547
8526
8071
8475
6682
9273
10 2
746
9791
1891
3204
8908
1495
1353
9406
1176
10 2
9884
6039
4691
9956
8516
9454
9649
8966
9380
...

output:

NO
YES
214 0
0 9328
0 0
0 8351
214 797
0 8760
214 209
0 8104
214 322
0 6834
NO
YES
144 0
0 7193
144 1676
0 7299
144 2104
0 6278
144 1649
0 6682
0 0
0 9273
NO
YES
3845 0
0 6039
0 0
0 4691
3845 1420
0 3251
3845 2358
0 3446
3845 1675
0 3860
NO
YES
2263 0
0 6695
1746 0
0 7879
1191 0
0 7854
54 0
0 9376
0...

result:

ok you are right!!

Test #6:

score: 5
Accepted
time: 0ms
memory: 5892kb

input:

10
10 2
7221
6762
7271
4154
1804
3226
6434
8357
2359
10 2
8581
5933
9174
9731
9716
9180
8744
9947
6264
10 2
282
9689
7228
960
2522
6806
7516
7002
9829
10 2
9202
8816
8250
9267
8287
8105
9707
8985
9226
10 2
2004
254
7197
7613
9790
5556
3064
6363
6489
10 2
7863
9827
9600
9998
7626
6038
9530
8772
8501
...

output:

NO
YES
2648 0
0 5933
0 0
0 9174
557 0
0 9159
21 0
0 8723
1224 0
0 5040
NO
YES
386 0
0 8816
0 0
0 8250
386 631
0 7270
386 449
0 8872
113 0
0 9113
NO
YES
0 0
0 7863
0 1964
0 7636
0 2362
0 5264
0 774
0 8756
0 16
0 8485
NO
YES
1850 0
0 6297
1850 881
0 4441
1850 3190
0 4724
1850 2842
0 5152
0 0
0 7789
YE...

result:

ok you are right!!

Test #7:

score: 5
Accepted
time: 1ms
memory: 5896kb

input:

10
10 2
2492
6642
8650
4949
7971
7552
5729
6137
3224
10 2
8862
4232
4370
9422
9787
8443
9745
9230
9708
10 2
1073
3311
5736
6108
1985
2880
2596
1260
4678
10 2
9862
9822
8867
4686
9645
7259
7954
9855
9482
10 2
6532
3248
1799
3767
7693
4389
5786
1124
9586
10 2
7667
9393
6828
8642
9482
8512
8366
7067
87...

output:

YES
0 0
0 2492
0 4150
0 4500
0 449
0 7522
0 30
0 5699
0 438
0 2786
YES
4630 0
0 4232
0 0
0 4370
4630 422
0 4735
3708 0
0 6037
3193 0
0 6515
NO
YES
6607 0
0 3255
6567 0
0 2300
2386 0
0 7259
0 0
0 7954
1901 0
0 7581
NO
YES
0 0
0 7667
0 1726
0 5102
0 3540
0 5942
0 2570
0 5796
0 1271
0 7506
NO
YES
913 0...

result:

ok you are right!!

Test #8:

score: 5
Accepted
time: 1ms
memory: 6264kb

input:

10
100 2
407406
741582
966880
693984
175204
991130
183615
326373
131306
366816
697972
180227
398068
835836
746523
999640
178807
545159
437329
536071
721606
306737
181599
455551
733444
231865
77996
588988
897019
804401
528918
524503
349494
623245
534144
344637
25518
791164
100668
547254
630911
346372...

output:

NO
YES
529624 0
0 220505
529624 100218
0 252235
529624 134665
0 330072
529624 118850
0 301947
529624 12582
0 133865
475779 0
0 117659
304071 0
0 382739
159037 0
0 783998
200904 0
0 576098
78459 0
0 784018
121346 0
0 475587
348606 0
0 568815
13833 0
0 979137
19943 0
0 575697
344429 0
0 517323
134004 ...

result:

ok you are right!!

Test #9:

score: 5
Accepted
time: 2ms
memory: 6512kb

input:

10
100 2
514849
121431
445450
996530
912655
547635
39581
89505
975458
843069
273144
700881
59053
289340
848708
32178
700710
194859
273472
213196
384827
341987
482545
308239
413944
599935
848280
843825
979288
195213
209986
440149
934390
768000
882462
200861
119570
174661
871708
511415
426500
576587
5...

output:

NO
YES
615952 0
0 377584
418860 0
0 579713
282384 0
0 512911
400157 0
0 577285
158607 0
0 841392
90635 0
0 842326
102411 0
0 802263
104644 0
0 820717
76607 0
0 919406
30968 0
0 821646
164428 0
0 578213
359654 0
0 323782
561344 0
0 314046
269602 0
0 729148
0 0
0 615762
346631 0
0 649282
298907 0
0 68...

result:

ok you are right!!

Test #10:

score: 5
Accepted
time: 1ms
memory: 6312kb

input:

10
100 2
650385
567657
465159
181316
696069
211308
655715
128129
988551
838473
44280
61031
528962
277047
286263
142130
248066
307713
578918
695526
89569
48119
569157
673222
295474
923221
90394
912892
523136
369133
635906
272262
887296
438346
625250
217263
729637
256075
898161
999382
845113
626531
74...

output:

NO
YES
864373 0
0 133199
698114 0
0 273481
709285 0
0 263356
348526 0
0 293622
676715 0
0 259457
180751 0
0 360307
587951 0
0 331511
496359 0
0 456555
186235 0
0 768865
200054 0
0 336105
0 0
0 740775
96579 0
0 861726
69309 0
0 590322
266038 0
0 470999
180716 0
0 667541
73026 0
0 797699
40641 0
0 750...

result:

ok you are right!!

Test #11:

score: 5
Accepted
time: 886ms
memory: 7776kb

input:

10
300 298
0 0 1 0 1 1 1 1 1 1 0 0 1 0 0 0 1 1 0 0 0 0 1 0 1 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 1 0 0 1 0 0 0 1 0 1 1 1 1 0 1 1 0 1 1 0 0 1 1 0 0 1 1 0 1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 1 0 0 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 1 0 1 0 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 1 0 1 1 0 1 1 1 0 0 0...

output:

NO
YES
1 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0...

result:

ok you are right!!

Test #12:

score: 5
Accepted
time: 871ms
memory: 7756kb

input:

10
297 296
0 0 1 0 1 0 1 0 1 1 0 1 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 1 0 0 1 1 1 0 0 0 1 1 1 1 1 0 0 1 1 0 1 1 1 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 0 1 0 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 0 1 1 1 1 1 1 1 0 0 0 1 1 0 1 1 1 1 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 1 1 0 1 0 0 1 1 0 0...

output:

NO
YES
1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0 1 0 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 0 1 0 0 1 0 1 0 0 0...

result:

ok you are right!!

Test #13:

score: 5
Accepted
time: 891ms
memory: 7452kb

input:

10
297 299
1 0 1 0 0 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 1 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 1 1 1 0 0 1 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 1 0 0 0 1 1 1 0 0 1 0 1 1 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1...

output:

NO
YES
0 0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 0 0 1 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 0 0 0 1 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 0 0 1 0 1 0 1 0 1 0 0 1 0 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0...

result:

ok you are right!!

Test #14:

score: 5
Accepted
time: 882ms
memory: 7788kb

input:

10
298 299
0 1 0 1 1 1 1 1 1 0 0 1 0 0 1 0 1 1 1 0 1 1 1 0 1 1 0 0 0 1 0 0 0 0 1 1 0 1 1 0 0 0 1 1 0 1 0 1 0 0 1 0 1 1 0 1 1 0 1 0 1 1 1 0 0 0 0 0 1 1 1 0 1 0 1 1 1 0 0 0 1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 0 1 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0 0 1 1 0...

output:

NO
YES
0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 1 0 1 0 0...

result:

ok you are right!!

Test #15:

score: 5
Accepted
time: 873ms
memory: 7496kb

input:

10
298 296
0 1 1 1 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 1 1 1 0 1 0 0 1 0 1 0 1 0 0 0 1 0 1 1 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 0 1 1 1 0 0 0 1 1 1 0 0 1 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 0 0 1 1 0 0 0 0 1 0 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1...

output:

NO
YES
1 0 0 1 0 1 0 0 1 0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0...

result:

ok you are right!!

Test #16:

score: 0
Time Limit Exceeded

input:

10
295 299
3600561 469227 1519243 508870 2714139 2548515 3416122 1633507 1829918 1551817 3098121 1670950 2106466 1946727 1581396 3426393 1988045 2888135 2146489 1534631 2721599 3729764 456043 293501 882439 3099151 2941143 3610816 549774 1066237 3189705 2413286 2316602 3976215 3845403 862960 241887 2...

output:

NO
YES
53148 357249 911227 367043 198202 294273 721555 762941 981775 513216 69137 438882 299674 279979 12200 313579 680872 578432 657299 181948 773103 322719 820609 971360 716103 559240 332552 355295 459715 13931 62619 820832 667279 231038 879173 909443 688013 256036 568120 212759 666137 456032 8755...

result:


Test #17:

score: 0
Time Limit Exceeded

input:

10
298 297
1203979 2459461 1123626 2165742 593951 2361185 60882 1597698 966249 1407808 2665213 1585110 1730464 732707 2642476 54357 96750 3459440 500455 1509802 2084769 1885656 824649 1394960 3065480 1964072 626742 582644 617926 652074 1646286 250370 1154127 1955950 327344 753408 2005921 2832519 933...

output:

NO
YES
504547 941148 191116 60624 387673 567730 441804 579360 534399 277214 151605 566867 571301 45423 717829 650274 984161 738763 330476 299642 313249 648217 219984 431856 227727 444385 241515 40357 523794 403579 881317 352945 842524 763889 799364 265374 25409 768899 147719 491765 729016 970417 234...

result:


Test #18:

score: 0
Time Limit Exceeded

input:

10
296 296
2917992 3146628 3606537 755096 2325656 3902232 2435726 2851482 3134088 1183312 3680091 2970485 3974463 2456731 3306154 400789 1137399 1266637 1849976 2126197 1039996 2867787 711979 2828033 1651264 3781772 1152035 2861694 2479767 1853717 886722 2972156 4583 903432 3364054 3947134 3871761 3...

output:

NO
YES
928870 332757 539014 225650 3082 852996 572883 110206 505546 703283 708817 703706 524208 416358 212848 420657 139226 362562 284138 361196 706494 544211 119513 339869 934581 785265 398007 93361 545002 225894 312860 572560 174803 0 525943 79395 856151 194120 908732 191775 839789 950995 86985 45...

result:


Test #19:

score: 0
Time Limit Exceeded

input:

10
297 297
13391 712464 2974864 1439202 1447544 1413180 800048 597109 3349875 2034207 1467293 796338 2354278 171222 1066675 2532591 208592 123178 2912280 3309432 3409173 1029236 2315777 2135394 3355241 69077 3113692 2937527 2948148 1151724 1640840 870814 42569 2304251 726055 3017332 2049772 2646010 ...

output:

NO
YES
329987 178535 497798 785959 795000 813833 778387 0 805219 839822 99771 714674 199100 705384 271541 166871 976376 943502 317570 60355 892355 270699 512433 84308 659078 329884 33475 432975 899897 330341 955859 311683 347175 720440 20164 445594 560495 339357 127224 646794 820948 793178 526636 17...

result:


Test #20:

score: 0
Time Limit Exceeded

input:

10
297 295
2251173 2102586 854138 210476 3746962 1050335 357886 1246625 2048656 3914401 2622120 2500826 3210040 3638713 646704 3538951 2675262 2202513 1600647 2451535 120429 782584 3574033 3344068 580591 2179489 3256587 684504 1805546 599720 3155847 2286982 2960267 502472 3365334 1420188 2393737 228...

output:

NO
YES
313320 845500 375344 598740 150835 828822 971611 2798 527378 971472 916360 578345 575619 797976 343329 230277 474141 771946 471736 112687 831331 582120 147158 983404 715848 983404 786024 361761 390186 771637 645792 644149 466328 553865 259452 14878 610866 123143 370991 354889 335563 706692 25...

result: