QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#345236 | #3416. First Date | PetroTarnavskyi# | TL | 0ms | 0kb | C++20 | 1.7kb | 2024-03-06 17:03:56 | 2024-03-06 17:03:57 |
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
VI days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool leap(int y)
{
if (y % 400 == 0)
return true;
if (y % 100 == 0)
return false;
if (y % 4 == 0)
return true;
return false;
}
string f(int y, int m, int d)
{
string t = to_string(y);
string s = "";
FOR (i, 0, 4 - SZ(t))
s += '0';
s += to_string(y);
s += '-';
if (m < 10)
s += '0';
s += to_string(m);
s += '-';
if (d < 10)
s += '0';
s += to_string(d);
return s;
}
int main()
{
unordered_map<string, string> mp;
mp.reserve(2e7);
int y1 = 1, m1 = 1, d1 = 1;
int y2 = 1, m2 = 1, d2 = 0;
while (y1 < 10000)
{
mp[f(y1, m1, d1)] = f(y2, m2, d2);
d1++;
if (y1 % 4 == 0)
days[1]++;
if (d1 > days[m1 - 1])
{
d1 -= days[m1 - 1];
m1++;
}
if (y1 % 4 == 0)
days[1]--;
if (m1 > 12)
{
m1 -= 12;
y1++;
}
d2++;
if (leap(y2))
days[1]++;
if (d2 > days[m2 - 1])
{
d2 -= days[m2 - 1];
m2++;
}
if (leap(y2))
days[1]--;
if (m2 > 12)
{
m2 -= 12;
y2++;
}
}
ios::sync_with_stdio(0);
cin.tie(0);
assert(accumulate(ALL(days), 0) == 365);
string s;
while (cin >> s)
{
cout << mp[s] << '\n';
}
cerr << clock() / db(CLOCKS_PER_SEC) << '\n';
return 0;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
1998-08-17 4382-11-10 4709-08-28 1665-01-25 1642-03-11 9866-12-11 2202-09-06 3839-09-02 6883-09-19 3518-11-09 8319-12-24 8308-04-19 8470-06-01 7764-08-23 8188-07-16 6485-07-25 7855-11-11 2208-06-20 4640-12-24 5498-07-01 9278-01-29 3798-09-03 9506-03-16 9058-08-18 5489-01-31 7624-03-14 7175-11-07 291...
output:
1998-08-31 4382-12-12 4709-10-02 1665-02-05 1642-03-22 9867-02-22 2202-09-22 3839-09-30 6883-11-08 3518-12-05 8320-02-24 8308-06-20 8470-08-02 7764-10-19 8188-09-14 6485-09-10 7856-01-08 2208-07-06 4641-01-27 5498-08-10 9278-04-07 3798-09-30 9506-05-26 9058-10-24 5489-03-12 7624-05-09 7175-12-30 291...