답안 #845055

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
845055 2023-09-06T11:42:39 Z vjudge1 Datum (COCI20_datum) C++17
40 / 50
1000 ms 468 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 18;

string pr(int a, int tp){
  string res = to_string(a);
  if(tp==0 || tp==1) if(res.length() == 2) return res; else return "0"+res;
  if(res.length() == 4) return res;
  if(res.length() == 3) return "0"+res;
  if(res.length() == 2) return "00"+res;
  return "000"+res;
}

bool check(array<int, 3>a ){
  string s = pr(a[0], 0) + pr(a[1],  1) + pr(a[2], 2);
  for(int i = 0; i < s.length()/2; ++i) if(s[i] != s[s.length()-1-i]) return false;
  return 1;
}


int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

array<int, 3> a;
void solve(){
  string s; cin >> s;
  a[0] = (s[0]-'0')*10 + (s[1]-'0');
  a[1] = (s[3]-'0')*10 + (s[4]-'0');
  a[2] = (s[6]-'0')*1000 + (s[7]-'0')*100 + (s[8]-'0')*10 + (s[9]-'0');
  while(true){
    // cout << a[0] << ' ' << a[1] << ' ' << a[2] << '\n';
    if(a[0] < month[a[1] - 1]) a[0]++;
    else if(a[0] >= month[a[1] - 1]){
      if(a[1] == 12){
        a[0] = 1, a[1] = 1;
        a[2]++;
      }else if(a[1] == 2){
        if(a[2] % 4 == 0){
          if(a[0] == 29){
            a[0] = 1;
            a[1]++;
          }else{
            a[0]++;
          }
        }else{
          a[0] = 1;
          a[1]++;
        }
      }else{
        a[1]++;
        a[0] = 1;
      }
    }
    if(check(a)){
      cout << pr(a[0], 0) << '.' << pr(a[1], 1) << '.' << pr(a[2], 2) << '.';
      return;
    }
  }
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  cin >> tt;
  while(tt--){
    solve();
    en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
}

Compilation message

datum.cpp: In function 'std::string pr(int, int)':
datum.cpp:14:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   14 |   if(tp==0 || tp==1) if(res.length() == 2) return res; else return "0"+res;
      |     ^
datum.cpp: In function 'bool check(std::array<int, 3>)':
datum.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for(int i = 0; i < s.length()/2; ++i) if(s[i] != s[s.length()-1-i]) return false;
      |                  ~~^~~~~~~~~~~~~~
datum.cpp: In function 'int main()':
datum.cpp:70:15: warning: unused variable 'aa' [-Wunused-variable]
   70 |   int tt = 1, aa;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 1064 ms 348 KB Time limit exceeded
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 105 ms 432 KB Output is correct
7 Correct 117 ms 344 KB Output is correct
8 Correct 135 ms 428 KB Output is correct
9 Correct 128 ms 428 KB Output is correct
10 Execution timed out 1032 ms 468 KB Time limit exceeded