Submission #845122

# Submission time Handle Problem Language Result Execution time Memory
845122 2023-09-06T12:05:42 Z vjudge1 Datum (COCI20_datum) C++17
50 / 50
225 ms 17488 KB
/**
 *  author: kututay
 *  created: 06.09.2023 14:29:47
**/
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
  #include "/Users/kutay/CP/templates/debug.h"
#else
  #define debug(...) void(38)
#endif

int32_t main() {
  ios_base::sync_with_stdio(0); cin.tie(0);

  auto check = [](int d, int m, int y) {
    string s = (d < 10 ? "0" + to_string(d) : to_string(d));
    s += (m < 10 ? "0" + to_string(m) : to_string(m));
    for (int i = 0; i < 4 - (int) to_string(y).size(); i++) {
      s += "0";
    }
    s += to_string(y);
    for (int i = 0; i <= (int) s.size() / 2; i++) {
      if (s[i] != s[(int) s.size() - i - 1]) return false;
    }
    return true;
  };
  vector<int> dd = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

  vector<pair<pair<int, int>, pair<int, int>>> v;
  int d = 1, m = 1, y = 1;
  vector<vector<vector<int>>> ddd(32, vector<vector<int>>(13, vector<int>(10000)));
  for (int day = 1; day < 4000000; day++) {
    if (y > 9999) break;
    ddd[d][m][y] = -day;
    if (check(d, m, y)) {
      v.push_back(make_pair(make_pair(day, d), make_pair(m, y)));
    }
    bool flag = false;
    if (y % 4 == 0) {
      dd[1] = 29;
      flag = true;
    }
    d++;
    if (d > dd[m - 1]) {
      m++;
      d = 1;
    }
    if (m > 12) {
      y++;
      m = 1;
    }
    if (flag) dd[1] = 28;
  }
  // debug(v);

  int t; cin >> t;
  while (t--) {
    string s; cin >> s;
    d = stoi(s.substr(0, 2)), m = stoi(s.substr(3, 2)), y = stoi(s.substr(6, 4));
    int day = ddd[d][m][y];
    if (day < 0) day = -day + 1;
    auto it = v[lower_bound(v.begin(), v.end(), make_pair(make_pair(day, 1), make_pair(1, 1))) - v.begin()];

    d = it.first.second, m = it.second.first, y = it.second.second;
    s = (d < 10 ? "0" + to_string(d) : to_string(d)) + ".";
    s += (m < 10 ? "0" + to_string(m) : to_string(m)) + ".";
    for (int i = 0; i < 4 - (int) to_string(y).size(); i++) {
      s += "0";
    }
    s += to_string(y) + ".";
    cout << s << '\n';
  }
}
# Verdict Execution time Memory Grader output
1 Correct 225 ms 17488 KB Output is correct
2 Correct 223 ms 17288 KB Output is correct
3 Correct 222 ms 17488 KB Output is correct
4 Correct 218 ms 17244 KB Output is correct
5 Correct 215 ms 17240 KB Output is correct
6 Correct 219 ms 17276 KB Output is correct
7 Correct 216 ms 17276 KB Output is correct
8 Correct 217 ms 17240 KB Output is correct
9 Correct 220 ms 17240 KB Output is correct
10 Correct 223 ms 17244 KB Output is correct