Submission #845304

# Submission time Handle Problem Language Result Execution time Memory
845304 2023-09-06T13:05:56 Z vjudge1 Datum (COCI20_datum) C++17
0 / 50
1000 ms 49296 KB
#include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define int long long
using namespace std;

const int inf = 2e18 + 5;
const int N = 5e3 + 5;
const int mod = 998244353;

string rev(string a){
 reverse(a.begin(), a.end());
 return a;
}

bool srt(string a, string b){
  string c = "", d = "";
  c += a[3];
  c += a[2];
  c += a[1];
  c += a[0];
  c += a[1];
  c += a[0];
  c += a[4];
  c += a[3];

  d += b[3];
  d += b[2];
  d += b[1];
  d += b[0];
  d += b[1];
  d += b[0];
  d += b[4];
  d += b[3];

  return c < d;
}

int32_t main(){
  freopen("in.txt","r", stdin);
  vector<int> m = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  vector<string> v;
  for(int i = 0; i <= 3112; i++){
    int bas1 = i/1000, bas2 = (i/100)%10, bas3 = (i/10)%10, bas4 = i%10;
    if(max(bas1, bas2) > 3 || max(bas1, bas2) < 1 || bas3 + bas4 == 0) continue;

    if(bas3 * 10 + bas4 <= 12 && bas3*10 + bas4 > 0){
        int ri = bas4 * 1000 + bas3*100 + bas2*10 + bas1;
        if(m[bas3 * 10 + bas4 - 1] + (bas3 * 10 + bas4 == 2 && ri%4 == 0 ? 1 : 0) >= bas1 * 10 + bas2 && bas1 + bas2 != 0){
            string a = "";
            a += (char)bas1 + '0';
            a += (char)bas2 + '0';
            a += (char)bas3 + '0';
            a += (char)bas4 + '0';
            v.pb(a);
        }
    }
  }
  sort(v.begin(), v.end(), srt);

  int n;
  cin>>n;
  while(n--){
    string s;
    cin>>s;
    string ss = "";
    ss += s[6];
    ss += s[7];
    ss += s[8];
    ss += s[9];
    ss += s[3];
    ss += s[4];
    ss += s[0];
    ss += s[1];

    string oh;
    for(int i = 0; i < v.size(); i++){
        string k = rev(v[i]) + v[i];
        if(k > ss){
            oh = v[i];
            break;
        }
    }

    cout<<oh[0]<<oh[1]<<"."<<oh[2]<<oh[3]<<"."<<rev(oh)<<"."<<endl;
  }

  return 0;
}

Compilation message

datum.cpp: In function 'int32_t main()':
datum.cpp:77:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for(int i = 0; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
datum.cpp:40:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   freopen("in.txt","r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1027 ms 48748 KB Time limit exceeded
2 Execution timed out 1040 ms 47372 KB Time limit exceeded
3 Execution timed out 1056 ms 47772 KB Time limit exceeded
4 Execution timed out 1048 ms 48140 KB Time limit exceeded
5 Execution timed out 1039 ms 49052 KB Time limit exceeded
6 Execution timed out 1006 ms 47212 KB Time limit exceeded
7 Execution timed out 1039 ms 49296 KB Time limit exceeded
8 Execution timed out 1046 ms 49116 KB Time limit exceeded
9 Execution timed out 1067 ms 48276 KB Time limit exceeded
10 Execution timed out 1022 ms 47752 KB Time limit exceeded