QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#345239#3416. First DatePetroTarnavskyi#AC ✓366ms395720kbC++201.8kb2024-03-06 17:09:472024-03-06 17:09:48

Judging History

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

  • [2024-03-06 17:09:48]
  • 评测
  • 测评结果:AC
  • 用时:366ms
  • 内存:395720kb
  • [2024-03-06 17:09:47]
  • 提交

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;
}

int toInt(int y, int m, int d)
{
	return (y * 100 + m) * 100 + d;
}

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<int, string> mp;
	mp.reserve(2e7);
	
	int y1 = 1, m1 = 1, d1 = 1;
	int y2 = 1, m2 = 1, d2 = 0;
	while (y1 < 10000)
	{
		mp[toInt(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)
	{
		int y = stoi(s.substr(0, 4)), m = stoi(s.substr(5, 2)), d = stoi(s.substr(8, 2));
		cout << mp[toInt(y, m, d)] << '\n';
	}
	cerr << clock() / db(CLOCKS_PER_SEC) << '\n';
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 353ms
memory: 395492kb

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...

result:

ok 100000 lines

Test #2:

score: 0
Accepted
time: 332ms
memory: 395624kb

input:

9500-01-01
9500-01-02
9500-01-03
9500-01-04
9500-01-05
9500-01-06
9500-01-07
9500-01-08
9500-01-09
9500-01-10
9500-01-11
9500-01-12
9500-01-13
9500-01-14
9500-01-15
9500-01-16
9500-01-17
9500-01-18
9500-01-19
9500-01-20
9500-01-21
9500-01-22
9500-01-23
9500-01-24
9500-01-25
9500-01-26
9500-01-27
950...

output:

9500-03-12
9500-03-13
9500-03-14
9500-03-15
9500-03-16
9500-03-17
9500-03-18
9500-03-19
9500-03-20
9500-03-21
9500-03-22
9500-03-23
9500-03-24
9500-03-25
9500-03-26
9500-03-27
9500-03-28
9500-03-29
9500-03-30
9500-03-31
9500-04-01
9500-04-02
9500-04-03
9500-04-04
9500-04-05
9500-04-06
9500-04-07
950...

result:

ok 182551 lines

Test #3:

score: 0
Accepted
time: 325ms
memory: 395484kb

input:

1582-10-04
1752-09-02
1900-02-25
1923-02-15

output:

1582-10-15
1752-09-14
1900-03-10
1923-03-01

result:

ok 4 lines

Test #4:

score: 0
Accepted
time: 313ms
memory: 395720kb

input:

1700-02-16
1700-02-17
1700-02-18
1700-02-19
1800-02-15
1800-02-16
1800-02-17
1800-02-18
1900-02-14
1900-02-15
1900-02-16
1900-02-17
2100-02-13
2100-02-14
2100-02-15
2100-02-16
2200-02-12
2200-02-13
2200-02-14
2200-02-15
2300-02-11
2300-02-12
2300-02-13
2300-02-14
2500-02-10
2500-02-11
2500-02-12
250...

output:

1700-02-27
1700-02-28
1700-03-01
1700-03-02
1800-02-27
1800-02-28
1800-03-01
1800-03-02
1900-02-27
1900-02-28
1900-03-01
1900-03-02
2100-02-27
2100-02-28
2100-03-01
2100-03-02
2200-02-27
2200-02-28
2200-03-01
2200-03-02
2300-02-27
2300-02-28
2300-03-01
2300-03-02
2500-02-27
2500-02-28
2500-03-01
250...

result:

ok 252 lines

Test #5:

score: 0
Accepted
time: 366ms
memory: 395564kb

input:

1582-10-04
1582-10-05
1582-10-06
1582-10-07
1582-10-08
1582-10-09
1582-10-10
1582-10-11
1582-10-12
1582-10-13
1582-10-14
1582-10-15
1582-10-16
1582-10-17
1582-10-18
1582-10-19
1582-10-20
1582-10-21
1582-10-22
1582-10-23
1582-10-24
1582-10-25
1582-10-26
1582-10-27
1582-10-28
1582-10-29
1582-10-30
158...

output:

1582-10-15
1582-10-16
1582-10-17
1582-10-18
1582-10-19
1582-10-20
1582-10-21
1582-10-22
1582-10-23
1582-10-24
1582-10-25
1582-10-26
1582-10-27
1582-10-28
1582-10-29
1582-10-30
1582-10-31
1582-11-01
1582-11-02
1582-11-03
1582-11-04
1582-11-05
1582-11-06
1582-11-07
1582-11-08
1582-11-09
1582-11-10
158...

result:

ok 189289 lines