Submission #845657

# Submission time Handle Problem Language Result Execution time Memory
845657 2023-09-06T14:46:54 Z vjudge1 Datum (COCI20_datum) C++17
40 / 50
15 ms 600 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const int inf =  100000000000000000LL;

string int_to_str(ll a, ll di)
{
    string ans="";
    for(int i = 0; i < di; ++i)
    {
        ans+=((char) (((ll)('0')) + a%10));
        a/=10;
    }
    reverse(ans.begin(),ans.end());
    return ans;
}
    
ll day(ll x) 
{
    ll d1=x/10; 
    ll d2=x%10; 
    return (10*d2+d1);
}
    
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll T; cin >> T;
    vector<ll> lim{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    vector<ll> a;
    for(int i = 0; i < 10000; ++i)
    {
        ll m=day(i/100);
        if(m>12 || m==0) {continue;}
        ll d=day(i%100);
        if(d==0 || d>lim[m-1]) {continue;}
        if(m==2 && d==29 && i%4!=0) {continue;}
        a.pb(d+100*m+10000*i);
    }
    for(int t = 0; t < T; ++t)
    {
        string s; cin>>s; 
        vector<ll> digits;
        for(int i = 0; i < s.size(); ++i)
        {
            if(s[i]=='.') {continue;}
            digits.pb((ll) (s[i]-'0'));
        }
        ll y=1000*digits[4]+100*digits[5]+10*digits[6]+digits[7];
        ll m=10*digits[2]+digits[3];
        ll d=10*digits[0]+digits[1];
        ll v=10000*y+100*m+d;
        ll ans=*upper_bound(a.begin(),a.end(),v);
        d=ans%100; ans/=100; m=ans%100; ans/=100; y=ans;
        cout << int_to_str(d,2) << "." << int_to_str(m,2) << "." << int_to_str(y,4) << "." << endl;
    }
    return 0;
}

Compilation message

datum.cpp:5:18: warning: overflow in conversion from 'long long int' to 'int' changes value from '100000000000000000' to '1569325056' [-Woverflow]
    5 | const int inf =  100000000000000000LL;
      |                  ^~~~~~~~~~~~~~~~~~~~
datum.cpp: In function 'int main()':
datum.cpp:46:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(int i = 0; i < s.size(); ++i)
      |                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 15 ms 600 KB Output isn't correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB Output isn't correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 15 ms 600 KB Output is correct