Submission #845321

# Submission time Handle Problem Language Result Execution time Memory
845321 2023-09-06T13:09:53 Z vjudge1 Datum (COCI20_datum) C++17
40 / 50
5 ms 600 KB
// author: erray
#include <bits/stdc++.h>

#ifdef DEBUG
  #include "debug.h"
#else
  #define debug(...) void(37)
#endif

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
      auto Day = [&](int x) {
        int r = x % 100;
        return r % 10 * 10 + (r / 10);
      };
      auto Month = [&](int x) {
        int r = x / 100;
        return r % 10 * 10 + (r / 10);
      };
      auto Leap = [&](int x) {
        return x % 4 == 0;
      };

  int TT;
  cin >> TT;
  while (TT--) {
    string D;
    cin >> D;
    int cur = 0, year = 0;
    auto C = [&](char c) {
      return c - '0';
    };
    cur = C(D[0]) + 10 * C(D[1]) + 100 * C(D[3]) + 1000 * C(D[4]);
    for (int i = 0, pw = 1; i < 4; ++i, pw *= 10) {
      year += pw * C(D.end()[-i - 2]);
    }
    debug(cur, year); 
    auto Find = [&](int y) {
      constexpr int days[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
      auto Valid = [&](int x) {
        int m = Month(x);
        return Day(x) > 0 && m <= 12 && m > 0 && (days[m] + (m == 2 && Leap(x)) >= Day(x)); 
      };
      debug("here");
      for (int add = 0; add < 100; ++add) {
        if (Valid(y + add)) {
          return y + add;
        }
      }
      debug(y);
      debug("bad");
      y -= y % 100;
      y += 1;
      while (!Valid(y)) {
        y += 100;  
      }
      debug(y);
      assert(Valid(y));
      return y;
      //divisible by 4 but not 100
    };
    int ans = Find(year);
    auto cd = array<int, 2>{C(D[4]) + 10 * C(D[3]), C(D[1]) + 10 * C(D[0])}; 
    debug(cd);
    if (ans == year && array<int, 2>{Month(year), Day(year)} <= cd) {
      ans = Find(year + 1);
    }
    debug(ans);
    string res;
    string yts = to_string(ans);
    while (yts.size() < 4) {
      yts.insert(yts.begin(), '0');
    }
    debug(D, yts);
    res += yts;
    reverse(res.begin(), res.end());
    res += yts;
    res.insert(res.begin() + 2, '.');
    res.insert(res.begin() + 5, '.');
    res.insert(res.end(), '.');
    cout << res << '\n';
  }  
}

Compilation message

datum.cpp: In function 'int main()':
datum.cpp:32:9: warning: variable 'cur' set but not used [-Wunused-but-set-variable]
   32 |     int cur = 0, year = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 5 ms 348 KB Output isn't correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Incorrect 5 ms 348 KB Output isn't correct