Submission #845149

# Submission time Handle Problem Language Result Execution time Memory
845149 2023-09-06T12:17:10 Z vjudge1 Datum (COCI20_datum) C++17
0 / 50
1 ms 600 KB
#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
using namespace std;

int mp[13] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
constexpr static int M = 100;
constexpr static int Y = 10000;
bool is_palindrome(const char* s)
{
	for (int i = 0; i < 4; i++)
		if (s[i] != s[7-i])
			return false;
	return true;
}

int32_t main()
{
	vector<int> v;
	for (int y = 1; y <= 9999; y++)
	{
		for (int m = 1; m <= 12; m++)
		{
			int td = mp[m];
			if (m == 2 && ((y%4) == 0))
				td = 29;
			for (int d = 1; d <= td; d++)
			{
				char ss[8];
				sprintf(ss, "%02d%02d%04d", d, m, y);
				if (is_palindrome(ss))
					v.pb(d + m * M + y * Y);
			}
		}
	}
	int q;
	cin >> q;
	while (q--)
	{
		string s;
		cin >> s;
		int d = (s[0]-'0') * 10 + (s[1]-'0'), m = (s[3]-'0') * 10 + (s[4]-'0'), y = (s[6]-'0') * 1000 + (s[7]-'0') * 100 + (s[8]-'0') * 10 + (s[9]-'0');
		int res = *upper_bound(v.begin(), v.end(), y * Y + m * M + d);
		printf("%02d.%02d.%04d.\n", res % M, (res % Y) / M, res / Y);
	}
}

Compilation message

datum.cpp: In function 'int32_t main()':
datum.cpp:30:21: warning: format '%d' expects argument of type 'int', but argument 3 has type 'int64_t' {aka 'long int'} [-Wformat=]
   30 |     sprintf(ss, "%02d%02d%04d", d, m, y);
      |                  ~~~^           ~
      |                     |           |
      |                     int         int64_t {aka long int}
      |                  %02ld
datum.cpp:30:25: warning: format '%d' expects argument of type 'int', but argument 4 has type 'int64_t' {aka 'long int'} [-Wformat=]
   30 |     sprintf(ss, "%02d%02d%04d", d, m, y);
      |                      ~~~^          ~
      |                         |          |
      |                         int        int64_t {aka long int}
      |                      %02ld
datum.cpp:30:29: warning: format '%d' expects argument of type 'int', but argument 5 has type 'int64_t' {aka 'long int'} [-Wformat=]
   30 |     sprintf(ss, "%02d%02d%04d", d, m, y);
      |                          ~~~^         ~
      |                             |         |
      |                             int       int64_t {aka long int}
      |                          %04ld
datum.cpp:44:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'int64_t' {aka 'long int'} [-Wformat=]
   44 |   printf("%02d.%02d.%04d.\n", res % M, (res % Y) / M, res / Y);
      |           ~~~^                ~~~~~~~
      |              |                    |
      |              int                  int64_t {aka long int}
      |           %02ld
datum.cpp:44:19: warning: format '%d' expects argument of type 'int', but argument 3 has type 'int64_t' {aka 'long int'} [-Wformat=]
   44 |   printf("%02d.%02d.%04d.\n", res % M, (res % Y) / M, res / Y);
      |                ~~~^                    ~~~~~~~~~~~~~
      |                   |                              |
      |                   int                            int64_t {aka long int}
      |                %02ld
datum.cpp:44:24: warning: format '%d' expects argument of type 'int', but argument 4 has type 'int64_t' {aka 'long int'} [-Wformat=]
   44 |   printf("%02d.%02d.%04d.\n", res % M, (res % Y) / M, res / Y);
      |                     ~~~^                              ~~~~~~~
      |                        |                                  |
      |                        int                                int64_t {aka long int}
      |                     %04ld
datum.cpp:30:30: warning: '__builtin___sprintf_chk' writing a terminating nul past the end of the destination [-Wformat-overflow=]
   30 |     sprintf(ss, "%02d%02d%04d", d, m, y);
      |                              ^
In file included from /usr/include/stdio.h:867,
                 from /usr/include/c++/10/cstdio:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:46,
                 from datum.cpp:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:34: note: '__builtin___sprintf_chk' output between 9 and 18 bytes into a destination of size 8
   36 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |       __bos (__s), __fmt, __va_arg_pack ());
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 6
2 Runtime error 1 ms 344 KB Execution killed with signal 6
3 Runtime error 1 ms 344 KB Execution killed with signal 6
4 Runtime error 1 ms 600 KB Execution killed with signal 6
5 Runtime error 0 ms 348 KB Execution killed with signal 6
6 Runtime error 1 ms 348 KB Execution killed with signal 6
7 Runtime error 0 ms 348 KB Execution killed with signal 6
8 Runtime error 1 ms 348 KB Execution killed with signal 6
9 Runtime error 1 ms 348 KB Execution killed with signal 6
10 Runtime error 1 ms 348 KB Execution killed with signal 6