Submission #2844755


Source Code Expand

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#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<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_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 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


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

ll solve(int N, string& S) {
    int P = 1 << N;
    char s1[20], s2[20];
    map<pair<string,string>,int> m1, m2;
    for (int p=0; p<P; ++p) {
        {
            int j=0, k=0;
            for (int i=0,b=1; i<N; ++i,b<<=1) {
                if (p & b) {
                    s1[j++] = S[i];
                } else {
                    s2[k++] = S[i];
                }
            }
            string u(s1,s1+j), v(s2,s2+k);
            ++m1[cons(u,v)];
        }
        {
            int j=0, k=0;
            for (int i=N*2-1,b=1; i>=N; --i,b<<=1) {
                if (p & b) {
                    s1[j++] = S[i];
                } else {
                    s2[k++] = S[i];
                }
            }
            string u(s1,s1+j), v(s2,s2+k);
            ++m2[cons(u,v)];
        }
    }
    // cerr << m1 << endl;
    // cerr << m2 << endl;
    ll ans = 0;
    for (auto p:m1) {
        ll c1 = p.second;
        ans += c1 * m2[p.first];
    }
    return ans;
}

int main() {
    int N; cin >> N;
    string S; cin >> S;
    cout << solve(N,S) << endl;
    return 0;
}

Submission Info

Submission Time
Task C - String Coloring
User naoya_t
Language C++14 (GCC 5.4.1)
Score 600
Code Size 3611 Byte
Status
Exec Time 935 ms
Memory 98560 KB

Compile Error

./Main.cpp: In function ‘void read_cr()’:
./Main.cpp:87:28: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
     fgets(_buf, 256, stdin);
                            ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 example_0, example_1, example_2, example_3
All 600 / 600 almost_z_0, almost_z_1, almost_z_2, almost_z_3, bigrand_0, bigrand_1, bigrand_2, example_0, example_1, example_2, example_3, handmade_0, handmade_1, nonzero_0, nonzero_1, nonzero_2, nonzero_3, nonzero_4, nonzero_5, nonzero_sc_0, nonzero_sc_1, nonzero_sc_10, nonzero_sc_11, nonzero_sc_2, nonzero_sc_3, nonzero_sc_4, nonzero_sc_5, nonzero_sc_6, nonzero_sc_7, nonzero_sc_8, nonzero_sc_9, nonzero_small_0, nonzero_small_1, nonzero_small_2, nonzero_small_3, rand_0, rand_1, rand_2, runnur_0, runnur_1, runnur_2, runnur_3, runnur_4
Case Name Status Exec Time Memory
almost_z_0 196 ms 256 KB
almost_z_1 207 ms 256 KB
almost_z_2 178 ms 256 KB
almost_z_3 192 ms 256 KB
bigrand_0 668 ms 63232 KB
bigrand_1 935 ms 98560 KB
bigrand_2 697 ms 71424 KB
example_0 1 ms 256 KB
example_1 4 ms 512 KB
example_2 1 ms 256 KB
example_3 167 ms 256 KB
handmade_0 1 ms 256 KB
handmade_1 1 ms 256 KB
nonzero_0 711 ms 66304 KB
nonzero_1 693 ms 69888 KB
nonzero_2 896 ms 98048 KB
nonzero_3 706 ms 73984 KB
nonzero_4 795 ms 80640 KB
nonzero_5 846 ms 98432 KB
nonzero_sc_0 226 ms 256 KB
nonzero_sc_1 319 ms 4608 KB
nonzero_sc_10 636 ms 54144 KB
nonzero_sc_11 542 ms 39808 KB
nonzero_sc_2 338 ms 10240 KB
nonzero_sc_3 464 ms 29184 KB
nonzero_sc_4 535 ms 41472 KB
nonzero_sc_5 766 ms 66176 KB
nonzero_sc_6 167 ms 256 KB
nonzero_sc_7 285 ms 3968 KB
nonzero_sc_8 337 ms 9472 KB
nonzero_sc_9 454 ms 18048 KB
nonzero_small_0 9 ms 1792 KB
nonzero_small_1 1 ms 256 KB
nonzero_small_2 1 ms 256 KB
nonzero_small_3 67 ms 9472 KB
rand_0 1 ms 256 KB
rand_1 1 ms 256 KB
rand_2 1 ms 256 KB
runnur_0 298 ms 6784 KB
runnur_1 248 ms 1024 KB
runnur_2 305 ms 1920 KB
runnur_3 264 ms 1792 KB
runnur_4 284 ms 4736 KB