# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
373057 | Nimbostratus | Datum (COCI20_datum) | C++14 | 32 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define pb push_back
#define ppb pop_back
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define cln(a,s) memset((a),0,sizeof((a)[0])*(s))
#define all(x) (x).begin() , (x).end()
#define fi first
#define se second
#define int int
using pii = pair<int,int>;
using ll = long long;
const int maxn = 2e5 + 5;
const int inf = 1e9;
const int mod = 1e9+7;
class date {
public:
string sday,smonth,syear;
int day,month,year;
date() {
day = inf;
month = inf;
year = inf;
}
date(string& sd,string& sm,string& sy) {
day = stoi(sd);
month = stoi(sm);
year = stoi(sy);
sday = sd;
smonth = sm;
syear = sy;
}
friend bool operator < (date& x , date& y) {
if(x.year < y.year) return true;
if(x.year > y.year) return false;
if(x.month < y.month) return true;
if(x.month > y.month) return false;
return x.day < y.day;
}
friend bool operator == (date& x , date& y) {
return x.year == y.year and x.month == y.month and x.day == y.day;
}
friend bool operator <= (date& x , date& y) {
return x < y or x == y;
}
};
int n;
string s;
vector<date> vec;
vector<int> days;
bool isvalid(date& x) {
if(x.month == 2 && x.day == 29) return x.year % 4 == 0;
if(x.month > 12 or x.month <= 0) return false;
if(x.day > days[x.month] or x.day <= 0) return false;
return true;
}
date datify() {
string day,month,year;
int i=0;
for(;i<s.size() && s[i] != '.';i++)
day += s[i];
i++;
for(;i<s.size() && s[i] != '.';i++)
month += s[i];
i++;
for(;i<s.size() && s[i] != '.';i++)
year += s[i];
return date(day,month,year);
}
int32_t main () {
//freopen("in","r",stdin); freopen("out","w",stdout);
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
days = {0,31,28,31,30,31,30,31,31,30,31,30,31};
for(char i='0';i<='3';i++)
for(char j='0';j<='9';j++)
for(char k='0';k<='1';k++)
for(char m='0';m<='9';m++) {
string day = string()+i+j;
string month = string()+k+m;
string year = day + month;
reverse(all(year));
date d(day,month,year);
if(isvalid(d)) {
vec.pb(d);
}
}
sort(all(vec));
/*for(date x : vec) {
cout << x.day << "." << x.month << "." << x.year << "." << endl;
}*/
//cout << endl;
cin >> n;
while(n--) {
cin >> s;
date x = datify();
int i;
for(i=0;i<vec.size() and vec[i]<=x;i++);
date d = vec[i];
cout << d.sday << "." << d.smonth << "." << d.syear << "." << endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |