fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<string> split_string(string);
  6.  
  7. // Complete the saveThePrisoner function below.
  8. int_least64_t saveThePrisoner(int n, int m, int s) {
  9. // pr-s, sweets, seat
  10. const int_least64_t seat =
  11. int_least64_t(s) + (int_least64_t(m) % int_least64_t(n)) - 1;
  12.  
  13. return (seat <= n) ? seat : (seat - n);
  14. }
  15.  
  16. int main()
  17. {
  18. ofstream fout(getenv("OUTPUT_PATH"));
  19.  
  20. int t;
  21. cin >> t;
  22. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  23.  
  24. for (int t_itr = 0; t_itr < t; t_itr++) {
  25. string nms_temp;
  26. getline(cin, nms_temp);
  27.  
  28. vector<string> nms = split_string(nms_temp);
  29.  
  30. int n = stoi(nms[0]);
  31.  
  32. int m = stoi(nms[1]);
  33.  
  34. int s = stoi(nms[2]);
  35.  
  36. int_least64_t result = saveThePrisoner(n, m, s);
  37.  
  38. std::cout << result << "\n";
  39. }
  40.  
  41. fout.close();
  42.  
  43. return 0;
  44. }
  45.  
  46. vector<string> split_string(string input_string) {
  47. string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
  48. return x == y and x == ' ';
  49. });
  50.  
  51. input_string.erase(new_end, input_string.end());
  52.  
  53. while (input_string[input_string.length() - 1] == ' ') {
  54. input_string.pop_back();
  55. }
  56.  
  57. vector<string> splits;
  58. char delimiter = ' ';
  59.  
  60. size_t i = 0;
  61. size_t pos = input_string.find(delimiter);
  62.  
  63. while (pos != string::npos) {
  64. splits.push_back(input_string.substr(i, pos - i));
  65.  
  66. i = pos + 1;
  67. pos = input_string.find(delimiter, i);
  68. }
  69.  
  70. splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
  71.  
  72. return splits;
  73. }
  74.  
Success #stdin #stdout 0s 15240KB
stdin
100
352926151 380324688 94730870
94431605 679262176 5284458
208526924 756265725 150817879
962975336 972576181 396355184
464237185 937820284 255816794
649320641 742902564 647542323
174512033 711706897 68977959
107283902 156676511 67149447
104513201 298399273 96292548
113378824 274011418 98103763
934815799 991959468 212396037
88325121 435452998 24617705
984873585 997634055 103050157
344218387 715364875 90658180
556065259 615709967 156417592
57109959 451440582 4188603
353972922 573651462 244520504
946486979 973168361 647886035
368127406 680428368 105517295
884634320 965112925 119757238
422557970 744431033 28932300
634954007 957414623 341366379
190265362 445253893 184632922
293315518 479153471 120684020
72410472 80198999 984948
784893322 849791807 360911386
846191883 880790237 510053756
297201660 812278057 198376746
945087694 999220046 465061514
786859800 831171414 378370933
528402029 859318899 224559950
522640531 755821672 28838424
864006909 879474138 806467486
613544440 943850900 258190755
734228459 928771704 265979283
542812502 597832172 330877768
541133561 748691081 126348492
51187317 524866691 1143193
885290374 990676850 373368385
147955933 450823700 138416059
100046465 587967212 32555061
233926824 996957988 31809378
785405778 835771758 689182705
444389615 870657324 72775880
702580369 895325888 345053199
968559651 974760313 326732084
299437419 514618345 254272806
901702945 930227426 727030891
721843209 736359383 225283784
833018320 883439261 806599246
267346244 307857609 46989880
299901304 892163356 210218436
565637506 795821687 158300457
107336562 781910357 54488503
513281286 916998022 254269425
413431205 611661371 188998419
740163288 938647312 571382392
44702121 296589002 43470596
771733011 919327188 317638907
718860003 815844769 495144331
377975600 438513404 111085209
424965480 928959619 20776133
234986523 732169039 205952749
377078343 981597420 219264561
612269027 791414524 580170106
232336090 616084008 81392003
75059328 274029861 53524881
239121359 646856043 141349731
923193147 943368157 206717532
12565064 536852817 11557940
360225746 970375527 284883902
213705306 380885426 14495860
659446919 699401237 73837176
335372713 785363124 7610828
538388654 859196325 110284314
118558760 713483972 83950807
896959032 961368580 8848444
25543240 521123082 2472730
258530682 935834352 194732411
465248213 679599042 334563499
331230504 637771661 76778140
976340152 988657462 243958260
552994811 922743535 540135280
626831986 839281366 24222267
157704591 253731033 59023773
806377559 859228114 238044289
838798445 996851254 268459446
847646888 928001503 755190846
877625009 999275937 874127074
847949466 893343194 10497830
35029316 784675240 8200127
111807455 690309882 23190325
355765714 554560093 311565654
1890615 614626804 976253
132293206 165429783 65360680
506726160 934170235 455394293
210041918 328800789 159203369
499999999 999999997 2
499999999 999999998 2
999999999 999999999 1
stdout
122129406
23525398
72975907
405956028
265162707
91803604
82636723
9258153
81152217
31978708
269539705
18445097
115810626
117586280
216062299
55859471
110226121
674567416
49690850
200235842
350805362
28872987
59090728
13206454
8773474
425809870
544652109
119049822
519193865
422682546
27074790
262019564
821934714
588497214
460522527
385897437
333906011
14136713
478754860
145371959
20243482
93060069
739548684
54653973
537798717
332932745
170016312
755555371
239799957
24001866
87501244
202677879
388484637
85042925
144704874
387228584
29703127
27144750
465233083
592129096
171623012
99804791
233162218
69626951
147046575
467740
27317429
70841696
226892541
8113004
174582190
181675979
113791493
122228525
431091984
86082218
73257991
12731011
96444034
83666114
52088792
256275569
356889192
236671646
155050214
290894843
426512254
835545460
118152992
55891557
22230414
42655476
154594318
1153181
98497256
376112207
67920321
499999999
1
0