답안 #845728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
845728 2023-09-06T15:07:09 Z vjudge1 Datum (COCI20_datum) C++17
40 / 50
4 ms 348 KB
#include <bits/stdc++.h>
#pragma optimize "DostSeferoğlu"
#pragma GCC optimize("unroll-loops,Ofast")
#pragma GCC target("avx2,tune=native")
using namespace std;
#define int long long
#define pii pair<int,int>
#define bg begin
#define vi vector<int>
#define endl '\n'
#define vvi vector<vi> 
#define pc __builtin_popcountll
#define vp vector<pii>
#define sp << " " << 
#define all(x) x.bg()+1,x.end()
#define ff first
#define ss second
#define brake {cout << "OK\n";return;}
#define debug(x) {cout << #x << ": "; for (auto it : x) cout << it << " ";cout << endl;}
#define FF(xxx,sss,yyy) for (int xxx=sss;xxx<=yyy;++xxx)
#define F(xx,yy) for (int xx=1;xx<=yy;++xx)
#define pb push_back 
const int inf = 1e18;
const int MOD = 998244353;   
const int N = 2e5+1;


string printyear(int year) {
    string ss = to_string(year);
    while (ss.size() < 4) {
        ss = "0"+ss;
    } 
    string ans;
    ans+=ss[3];
    ans+=ss[2];
    ans+='.';
    ans+=ss[1];
    ans+=ss[0];
    ans+='.';
    ans+=ss;
    ans+='.';
    return ans;
}

void solve() {
    int q;
    cin >> q;
    vector<int> goodyears;
    vi cap(13);
    cap = {0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31};
    for (int y=0;y<=9999;y++) {
        string s = to_string(y);
        while (s.size() < 4) s = "0"+s;
        string month;
        month+=s[1];
        month+=s[0];
        if (stoi(month) > 12 || !stoi(month)) continue;
        string day;
        day+=s[3];
        day+=s[2];
        if (y%4 == 0) cap[2]++;
        int m = stoi(month);
        int d = stoi(day);
        if (d>cap[m] || !stoi(day)) {
            if (y%4 == 0) cap[2]--;
            continue;
        }
        if (y%4 == 0) cap[2]--;
        goodyears.pb(y);
        //cout << printyear(y) << endl;
    }
    while (q--) {
        string s;
        cin >> s;
        string year;
        year+=s[6];
        year+=s[7];
        year+=s[8];
        year+=s[9];
        int y = stoi(year);
        int x = *lower_bound(goodyears.bg(),goodyears.end(),y);
        int x2 = *upper_bound(goodyears.bg(),goodyears.end(),y);
        string p = printyear(x);
        int thismonth = 10*(s[3]-'0')+(s[4]-'0');
        int thisday = 10*(s[0]-'0')+(s[1]-'0');
        int thatyear = 1000*(p[6]-'0')+100*(p[7]-'0')+10*(p[8]-'0')+(p[9]-'0');
        int thatmonth = 10*(p[3]-'0')+(p[4]-'0');
        int thatday = 10*(p[0]-'0')+(p[1]-'0');
        if (thatyear > y) {
            cout << p << endl;
            continue;;
        }
        if (thatmonth > thismonth) {
            cout << p << endl;
            continue;
        }
        if (thatday > thisday) {
            cout << p << endl;
            continue;;
        }
        cout << printyear(x2) << endl;
    }
}    



signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);
    #ifdef Local
        freopen("input.in", "r", stdin);
        freopen("input.out", "w", stdout);  
    #endif
    int t = 1;
    //cin >> t;
    while (t --> 0) solve();
}

Compilation message

datum.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    2 | #pragma optimize "DostSeferoğlu"
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 4 ms 348 KB Output isn't correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Incorrect 3 ms 344 KB Output isn't correct