답안 #219338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
219338 2020-04-05T07:13:23 Z VEGAnn Datum (COCI20_datum) C++14
50 / 50
515 ms 57876 KB
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define PB push_back
using namespace std;
const int N = 4000100;
const int oo = 2e9;
string s, t;
vector<array<int, 3> > vc;
int moths[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int nearest[N];

string tostr(int x, int len){
    string res = "";

    for (int it = 0; it < len; it++){
        res += char(x % 10 + '0');
        x /= 10;
    }

    reverse(all(res));

    return res;
}

bool pali(int id){
    s = "";
    s += tostr(vc[id][2], 2);
    s += tostr(vc[id][1], 2);
    s += tostr(vc[id][0], 4);
    t = s;
    reverse(all(t));

    return (s == t);
}

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

//    freopen("in.txt","r",stdin);

    for (int year = 1; year < 10000; year++)
        for (int mon = 0; mon < 12; mon++){
            int kol_days = moths[mon];

            if (year % 4 == 0 && mon == 1)
                kol_days++;

            for (int days = 1; days <= kol_days; days++)
                vc.PB({year, mon + 1, days});
        }

    nearest[sz(vc) - 1] = sz(vc);

    for (int i = sz(vc) - 2; i >= 0; i--)
        if (pali(i + 1))
            nearest[i] = i + 1;
        else nearest[i] = nearest[i + 1];

    int qq; cin >> qq;

    for (; qq; qq--){
        int d = 0, m = 0, y = 0;
        char c;

        cin >> c; d = d * 10 + (c - '0');
        cin >> c; d = d * 10 + (c - '0');
        cin >> c;

        cin >> c; m = m * 10 + (c - '0');
        cin >> c; m = m * 10 + (c - '0');
        cin >> c;

        cin >> c; y = y * 10 + (c - '0');
        cin >> c; y = y * 10 + (c - '0');
        cin >> c; y = y * 10 + (c - '0');
        cin >> c; y = y * 10 + (c - '0');
        cin >> c;

        array<int, 3> ar = {y, m, d};

        int loc = lower_bound(all(vc), ar) - vc.begin();

        int id = nearest[loc];

        cout << tostr(vc[id][2], 2) << "." << tostr(vc[id][1], 2) << "." << tostr(vc[id][0], 4) << ".\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 489 ms 57716 KB Output is correct
2 Correct 506 ms 57848 KB Output is correct
3 Correct 485 ms 57720 KB Output is correct
4 Correct 499 ms 57876 KB Output is correct
5 Correct 514 ms 57720 KB Output is correct
6 Correct 515 ms 57596 KB Output is correct
7 Correct 512 ms 57848 KB Output is correct
8 Correct 498 ms 57720 KB Output is correct
9 Correct 485 ms 57592 KB Output is correct
10 Correct 511 ms 57856 KB Output is correct