编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#46951 #112. czq的时间间隔 Accepted 100 30 ms 376 K C++ 17 / 2.6 K 20183400732 2020-12-22 18:17:36
显示原始代码
#include <bits/stdc++.h>
#define DB double
#define LL long long

#define MST(a, b) memset((a), (b), sizeof(a))
#define MRK() cout << "Mark" << endl;
#define WRT(x) cout << #x << " = " << (x) << endl;

#define MAXN 210000
#define MAXM 410000
#define MOD 998244353
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-5

#define _ 0
using namespace std;

#define int LL
const int second_per_day = 24 * 60 * 60;
const int second_per_hour = 60 * 60;
const int second_per_minute = 60;

const int day_per_month[2][13] = { { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
                                   { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } };

int check(int year) {
    if (year % 4 == 0 && year % 100 != 0)
        return 1;
    if (year % 400 == 0)
        return 1;
    return 0;
}

bool validator(int year, int month, int day, int hour, int minute, int second) {
    if (year == 0)
        return false;
    if (month < 0 || month > 12)
        return false;
    if (day <= 0 || day > day_per_month[check(year)][month])
        return false;
    if (hour < 0 || hour >= 24)
        return false;
    if (minute < 0 || minute >= 60)
        return false;
    if (second < 0 || second >= 60)
        return false;
    return true;
}

LL getstamp(int year, int month, int day, int hour, int minute, int second) {
    LL ans = 0;
    LL tmp = 0;
    tmp = (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400;
    ans += (tmp * 366 + (year - 1 - tmp) * 365) * second_per_day;
    for (int i = 1; i < month; i++) ans += day_per_month[check(year)][i] * second_per_day;
    ans += (day - 1) * second_per_day;
    ans += hour * second_per_hour;
    ans += minute * second_per_minute;
    ans += second;
    return ans;
}

LL getId(int y, int m, int d, int h, int mi, int s) {
    if (m < 3) {
        y--;
        m += 12;
    }
    LL D = 365 * y + y / 4 - y / 100 + y / 400 + (153 * (m - 3) + 2) / 5 + d - 307;
    return D * 86400 + h * 3600 + mi * 60 + s;
}

LL getans() {
    int year, month, day, hour, minute, second;
    scanf("%lld/%lld/%lld %lld:%lld:%lld", &year, &month, &day, &hour, &minute, &second);
    if (!validator(year, month, day, hour, minute, second))
        return -1;
    return getId(year, month, day, hour, minute, second);
}

void work() {
    LL s1 = getans();
    LL s2 = getans();
    if (s1 == -1 || s2 == -1)
        cout << -1 << endl;
    else if (s1 > s2)
        cout << s1 - s2 << endl;
    else
        cout << s2 - s1 << endl;
}
signed main() {
    int t;
    cin >> t;
    while (t--) work();
    return ~~(0 ^ _ ^ 0);
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:4 ms
内存:312 KiB

输入文件(1.in

14
2020/08/22 23:48:00 2020/08/22 23:48:59
2020/08/22 23:48:59 2020/08/22 23:48:00
2020/08/22 23:22:
<463 bytes omitted>

答案文件(1.out

59
59
1537
82527
1032927
21164127
17902896185
-1
-1
-1
-1
-1
-1
315537897599

用户输出

59
59
1537
82527
1032927
21164127
17902896185
-1
-1
-1
-1
-1
-1
315537897599

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:26 ms
内存:376 KiB

输入文件(2.in

10000
5348/13/26 20:09:36 5809/10/09 11:17:33
8951/13/09 02:54:35 1245/10/20 19:37:36
7524/01/04 20:
<399906 bytes omitted>

答案文件(2.out

-1
-1
52181193949
167527773820
11151421677
176367406636
34137847390
71087537213
156479412870
<102130 bytes omitted>

用户输出

-1
-1
52181193949
167527773820
11151421677
176367406636
34137847390
71087537213
156479412870
-1
-1
81508312928
163816674890
-1
6
<92102 bytes omitted>

系统信息

Exited with return code 0