Submission #3909323


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }
template<typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template<typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }



int stat[64][64][64];
bool dp[64][64][64];
string maxs;
int maxv=-1;

void scan(char* buf) {
    int L = strlen(buf);
    if (buf[L-1] < 32) --L;
    if (buf[L-1] < 32) --L;
    buf[L] = 0;

    mset(dp, 0);
    dp[0][0][0] = true;

    rep(at,L) {
        int ch = buf[at] - 64;
        assert(IN(ch,0,63));

        rep(ih,2) rep(il,26) {
            int i = 0x41 + 0x20*ih + il - 64;

            rep(jh,2) rep(jl,26) {
                int j = 0x41 + 0x20*jh + jl - 64;

                if (!dp[i][j][0]) continue;

                if (!dp[i][j][ch]) {
                    string s { (char)(64+i), (char)(64+j), (char)(64+ch) };
                    ++stat[i][j][ch];
                    if (stat[i][j][ch] > maxv
                       || (stat[i][j][ch] == maxv && s < maxs)) {
                        maxv = stat[i][j][ch];
                        maxs = s;
                    }
                    dp[i][j][ch] = true;
                }
            }

            if (!dp[i][0][0]) continue;

            dp[i][ch][0] = true;
        }

        dp[ch][0][0] = true;
    }
}


int main() {
    char buf[90010];
    fgets(buf, 256, stdin);
    int N = atoi(buf);

    maxs.assign(3, '~');
    maxv = -1;

    mset(stat, 0);
    rep(i,N){
        fgets(buf, 90010, stdin);
        scan(buf);
    }

    cout << maxs << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Three Letters
User naoya_t
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3244 Byte
Status

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:101:27: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
     fgets(buf, 256, stdin);
                           ^
./Main.cpp:109:33: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
         fgets(buf, 90010, stdin);
                                 ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt
All 0 / 500 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
01.txt 549 ms 1536 KB
02.txt 490 ms 1664 KB
03.txt 630 ms 1536 KB
04.txt 1984 ms 1536 KB
05.txt
06.txt 1319 ms 1536 KB
07.txt 441 ms 1536 KB
08.txt
09.txt 448 ms 1536 KB
10.txt 815 ms 1536 KB
11.txt 572 ms 1536 KB
12.txt 575 ms 1536 KB
13.txt 578 ms 1536 KB
sample_01.txt 2 ms 1536 KB
sample_02.txt 2 ms 1536 KB