QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#49801#2013. 儒略日james1BadCreeper100 ✓81ms3788kbC++172.7kb2022-09-23 09:48:432022-09-23 09:48:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-23 09:48:44]
  • 评测
  • 测评结果:100
  • 用时:81ms
  • 内存:3788kb
  • [2022-09-23 09:48:43]
  • 提交

answer

#include <iostream>
#include <cstdio>

#define i64 long long

using namespace std;

int MonthDay[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

inline void print(int year, int month, int day)
{
    if (year < 0) printf("%d %d %d BC\n", day, month, -year);
    else printf("%d %d %d\n", day, month, year);
}

inline void calc_julian(i64 x)
{
    int year, month = 1, day = 1, flag;
    int raw = (365 << 2) + 1;

    if (x < 1721424) year = -4713, flag = 1;
    else x -= 1721424, year = 1, flag = 4;

    year += x / raw * 4;
    x = x % raw;

    for (int i = 1; i <= 4; ++i)
    {
        int col = 365;
        if (i == flag) col = 366;
        if (x >= col) ++year, x -= col;
        else
        {
            if (i == flag) MonthDay[2] = 29;
            else MonthDay[2] = 28;
            for (int j = 1; j <= 12; ++j)
                if (x >= MonthDay[j]) x -= MonthDay[j], ++month;
                else
                {
                    day += x;
                    break;
                }
            break;
        }
    }

    print(year, month, day);
}

inline void calc_1583(i64 x)
{
    int year = 1582, month = 10, day = 15;
    x -= 2299161;
    if (x < 17) print(year, month, day + x);
    else
    {
        x -= 17;
        month = 11, day = 1;
        if (x < 30) print(year, 11, day + x);
        else
        {
            x -= 30;
            month = 12, day = 1;
            print(year, 12, day + x);
        }
    }
}

inline bool check(int x)
{
    if (x == 18) return true;
    if (x == 118 || x == 218 || x == 318) return false;
    if ((x + 2) % 4 == 0) return true;
    return false;
}

inline void calc_gregorian(i64 x)
{
    x -= 2299239;
    int year = 1583, month = 1, day = 1;
    int raw = 365 * 400 + 97;

    year += x / raw * 400;
    x %= raw;

    for (int i = 1; i <= 400; ++i)
    {
        int checker = check(i), col = 365;
        if (checker) col = 366;
        if (x >= col) ++year, x -= col;
        else
        {
            if (checker) MonthDay[2] = 29;
            else MonthDay[2] = 28;
            for (int j = 1; j <= 12; ++j)
                if (x >= MonthDay[j]) x -= MonthDay[j], ++month;
                else
                {
                    day += x;
                    break;
                }
            break;
        }
    }

    print(year, month, day);
}

int main(void)
{
    int T; scanf("%d", &T);
    while (T--)
    {
        i64 x; scanf("%lld", &x);
        if (x < 2299161) calc_julian(x);
        else 
        {
            if (x < 2299239) calc_1583(x);
            else calc_gregorian(x);
        }
    }   
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 3ms
memory: 3788kb

input:

1000
257
299
19
191
19
48
350
193
354
309
128
347
57
49
216
234
185
360
112
43
254
237
89
188
34
147
243
110
300
245
130
190
240
350
106
342
294
198
94
128
166
330
328
22
212
19
344
250
243
177
241
139
127
210
186
61
151
244
251
291
351
18
73
106
53
156
256
304
318
68
181
312
309
269
357
253
196
257...

output:

14 9 4713 BC
26 10 4713 BC
20 1 4713 BC
10 7 4713 BC
20 1 4713 BC
18 2 4713 BC
16 12 4713 BC
12 7 4713 BC
20 12 4713 BC
5 11 4713 BC
8 5 4713 BC
13 12 4713 BC
27 2 4713 BC
19 2 4713 BC
4 8 4713 BC
22 8 4713 BC
4 7 4713 BC
26 12 4713 BC
22 4 4713 BC
13 2 4713 BC
11 9 4713 BC
25 8 4713 BC
30 3 4713 BC...

result:

ok 1000 lines

Test #2:

score: 10
Accepted
time: 3ms
memory: 3736kb

input:

1000
6395
3251
8793
7077
5270
1291
27
6247
2762
1885
3093
9099
5392
8247
4847
2637
5425
2725
6470
1341
9583
2544
7631
1256
5269
1960
9335
553
1888
8566
9889
2986
4554
4446
9796
6608
6251
1662
9865
2202
2756
6514
891
1755
7657
1181
3963
4130
3900
6986
5878
3618
5074
6251
3336
4238
3620
1849
3558
4971...

output:

5 7 4696 BC
25 11 4705 BC
28 1 4689 BC
18 5 4694 BC
6 6 4699 BC
15 7 4710 BC
28 1 4713 BC
7 2 4696 BC
25 7 4706 BC
28 2 4708 BC
20 6 4705 BC
29 11 4689 BC
6 10 4699 BC
31 7 4691 BC
9 4 4700 BC
22 3 4706 BC
8 11 4699 BC
18 6 4706 BC
18 9 4696 BC
3 9 4710 BC
28 3 4687 BC
19 12 4707 BC
22 11 4693 BC
10...

result:

ok 1000 lines

Test #3:

score: 10
Accepted
time: 2ms
memory: 3744kb

input:

1000
27743
23166
87004
36061
830
54943
26997
78474
34587
92526
60959
78723
24515
67427
52309
90785
87635
7524
65271
77534
42849
47319
95652
93924
94481
21222
47423
52435
27180
64606
64921
52650
48949
53415
57647
88417
49043
72939
24728
66810
72203
55819
82016
53124
78629
39299
12136
49440
63976
5437...

output:

16 12 4638 BC
5 6 4650 BC
16 3 4475 BC
24 9 4615 BC
10 4 4711 BC
5 6 4563 BC
30 11 4640 BC
7 11 4499 BC
11 9 4619 BC
28 4 4460 BC
24 11 4547 BC
14 7 4498 BC
13 2 4646 BC
9 8 4529 BC
20 3 4570 BC
22 7 4465 BC
7 12 4474 BC
7 8 4693 BC
14 9 4535 BC
11 4 4501 BC
25 4 4596 BC
21 7 4584 BC
18 11 4452 BC
2...

result:

ok 1000 lines

Test #4:

score: 10
Accepted
time: 6ms
memory: 3760kb

input:

10000
299452
283862
233477
48022
195762
294033
82643
237130
33910
143114
129810
109179
138459
230072
287636
21837
5051
11636
28382
246448
158609
9683
86265
16051
64723
4441
152139
152618
61633
199844
185145
226504
231773
84337
117518
45755
92966
271348
101884
73015
121278
291837
41657
151437
23662
1...

output:

9 11 3894 BC
4 3 3936 BC
24 3 4074 BC
24 6 4582 BC
20 12 4178 BC
7 1 3908 BC
7 4 4487 BC
24 3 4064 BC
3 11 4621 BC
29 10 4322 BC
27 5 4358 BC
1 12 4415 BC
30 1 4334 BC
26 11 4084 BC
4 7 3926 BC
15 10 4654 BC
30 10 4700 BC
10 11 4682 BC
15 9 4636 BC
27 9 4039 BC
1 4 4279 BC
6 7 4687 BC
7 3 4477 BC
12...

result:

ok 10000 lines

Test #5:

score: 10
Accepted
time: 0ms
memory: 3752kb

input:

10000
1744649
360536
384324
1822443
1997965
1802407
427330
2056152
604801
2112704
793668
578388
1655386
2051558
1197508
2358488
1182551
2381194
136013
849577
1667858
2183990
892695
1003065
1757854
1128153
2059716
528642
2356262
669644
463190
1515053
1897644
2332591
42359
350204
426097
1133457
215574...

output:

3 8 64
4 2 3726 BC
22 3 3661 BC
30 7 277
17 2 758
21 9 222
19 12 3544 BC
9 6 917
9 11 3058 BC
8 4 1072
11 12 2541 BC
17 7 3130 BC
14 3 181 BC
10 11 904
7 8 1435 BC
21 3 1745
25 8 1476 BC
22 5 1807
20 5 4341 BC
6 1 2387 BC
7 5 147 BC
10 6 1267
25 1 2269 BC
30 3 1967 BC
28 9 100
18 9 1625 BC
13 3 927
...

result:

ok 10000 lines

Test #6:

score: 10
Accepted
time: 32ms
memory: 3680kb

input:

100000
1950875
150500
718861
2414166
956849
2305579
205931
915700
2307512
1998760
937618
953209
823763
177854
7984
234733
2064957
1141241
2368883
915076
1616203
176585
2165292
1521597
1645854
642841
803087
1160000
1466677
2298153
2296446
609273
2439738
787459
1668490
1828136
725337
1916028
70052
812...

output:

16 3 629
18 1 4301 BC
19 2 2745 BC
29 8 1897
17 9 2094 BC
11 5 1600
23 10 4150 BC
19 1 2206 BC
26 8 1605
22 4 760
22 1 2146 BC
29 9 2104 BC
5 5 2458 BC
9 12 4227 BC
10 11 4692 BC
31 8 4071 BC
18 7 941
19 7 1589 BC
5 9 1773
5 5 2208 BC
3 12 289 BC
19 6 4230 BC
31 3 1216
27 11 548 BC
7 2 207 BC
2 1 29...

result:

ok 100000 lines

Test #7:

score: 10
Accepted
time: 44ms
memory: 3676kb

input:

100000
1973649
1481694
4758778
2447407
533994
1409912
1974136
1581496
2416488
496139
3891556
4067841
2024440
2368816
578377
3778127
3158195
4163079
4019230
1149867
2751681
2630258
2241499
3782746
3202138
4661894
4864201
3714028
506929
361403
102401
1775088
1408294
2902197
2747737
2849127
2807562
315...

output:

23 7 691
28 8 657 BC
28 12 8316
2 9 1988
30 12 3252 BC
17 2 853 BC
21 11 692
25 11 384 BC
8 1 1904
10 5 3355 BC
14 8 5942
8 4 6425
13 8 830
30 6 1773
6 7 3130 BC
22 1 5632
29 9 3934
8 1 6686
5 3 6292
1 3 1565 BC
29 9 2821
19 4 2489
21 11 1424
14 9 5644
20 1 4055
24 9 8051
18 8 8605
24 7 5456
24 11 3...

result:

ok 100000 lines

Test #8:

score: 10
Accepted
time: 65ms
memory: 3676kb

input:

100000
3543827
8074270
6832682
4183997
1752513
8424605
351437
6684898
8699196
6917186
3880104
8448705
5062449
9564280
2259414
5948578
5822877
2206752
2840952
4147277
9626255
2562967
6231082
8401292
9755178
2009057
4412064
6627523
4652026
6467617
4814280
6489656
7327228
179839
8975748
6756021
3733120...

output:

26 7 4990
1 7 17394
23 2 13995
18 4 6743
13 2 86
7 9 18353
8 3 3751 BC
12 7 13590
28 6 19105
6 7 14226
7 4 5911
1 9 18419
31 5 9148
3 1 21474
9 12 1473
21 7 11574
24 5 11230
4 10 1329
28 2 3066
4 10 6642
9 9 21643
24 1 2305
9 1 12348
8 11 18289
1 9 21996
1 7 788
20 9 7367
10 6 13433
17 9 8024
19 8 1...

result:

ok 100000 lines

Test #9:

score: 10
Accepted
time: 81ms
memory: 3780kb

input:

100000
969863255
512041578
700605139
629561710
176210458
857786204
223724105
16051729
694452902
307653258
282757293
614942851
294634803
564771723
50714034
846186580
456544296
493671055
392020928
254552455
78296891
55098482
147093119
732617546
697549814
97389537
901576955
61661837
556724721
334567477...

output:

20 4 2650683
14 2 1397210
14 8 1913479
25 4 1718969
30 9 477735
4 10 2343826
11 9 607823
15 1 39236
14 5 1896635
28 11 837613
27 1 769451
28 3 1678944
4 8 801970
10 5 1541580
17 3 134138
24 1 2312068
22 9 1245263
4 5 1346913
29 9 1068604
6 11 692228
3 7 209657
2 6 146142
7 3 398015
12 8 2001126
4 6 ...

result:

ok 100000 lines

Test #10:

score: 10
Accepted
time: 66ms
memory: 3740kb

input:

100000
34363893340
236277310612
166702662888
268993603588
18645082198
297103581763
198899033171
11086173697
315120559948
275759021654
78354393827
237924397441
238669363893
185565970407
271541872488
45956191485
323595620132
6873148734
264282494825
158735073101
241370346760
348392536375
352566583390
9...

output:

5 4 94080432
19 3 646900592
13 9 456411676
31 12 736474759
3 2 51043789
17 3 813437266
2 7 544562344
18 7 30348200
9 1 862766077
11 7 754997845
15 10 214522331
14 10 651410162
28 8 653449811
14 7 508057658
10 4 743451683
31 7 125819066
9 9 885970003
23 12 18813329
21 4 723576182
18 10 434597156
28 7...

result:

ok 100000 lines

Extra Test:

score: 0
Extra Test Passed