Submission #372405


Source Code Expand

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;

const int INF = 1e9;
const int MOD = 1e9+7;

typedef ll Data;
struct Trie{
    Data data;
    Data m;
    bool tail;
    Trie *prev;
    Trie *next[10];
    Trie(){data=0LL;m=0LL;tail=false;prev=(Trie*)0;fill(next, next+10, (Trie*)0);}
};
void insert(char *t, Trie *r, Data data=0){
    //cout << "char :" << *t << endl;
    if(!(*t)){
        r->data = r->data + data;
        r->m = r->m + data;
        Data m = 0LL;
        m = r->m;
        while(r->data != -1LL){
            r = r->prev;
            m = max(r->m, m + r->data);
            r->m = m;
        }
        return;
    }
    int c = (*t) - '0';
    if(!r->next[c]){
        r->next[c] = new Trie();
        r->next[c]->prev = r;
    }
    insert(t+1, r->next[c], data);
}

int main(void){
    int n;
    cin >> n;
    Trie *top = new Trie();
    top->data = -1;
    REP(i, n){
        string ss; int k;
        cin >> ss >> k;
        char s[15];
        REP(j, ss.size()){
            s[j] = ss[ss.size()-j-1];
            s[j+1] = '\0';
        }
        insert(s, top, k);
        cout << top->m + 1 << endl; 
    }

    return 0;
}

Submission Info

Submission Time
Task E - 宝くじ
User itf
Language C++ (GCC 4.9.2)
Score 200
Code Size 1813 Byte
Status AC
Exec Time 793 ms
Memory 64660 KiB

Judge Result

Set Name All
Score / Max Score 200 / 200
Status
AC × 25
Set Name Test Cases
All scrambled_00.txt, scrambled_01.txt, scrambled_02.txt, scrambled_03.txt, scrambled_04.txt, scrambled_05.txt, scrambled_06.txt, scrambled_07.txt, scrambled_08.txt, scrambled_09.txt, scrambled_10.txt, scrambled_11.txt, scrambled_12.txt, scrambled_13.txt, scrambled_14.txt, scrambled_15.txt, scrambled_16.txt, scrambled_17.txt, scrambled_18.txt, scrambled_19.txt, scrambled_20.txt, scrambled_21.txt, scrambled_22.txt, scrambled_23.txt, scrambled_24.txt
Case Name Status Exec Time Memory
scrambled_00.txt AC 27 ms 804 KiB
scrambled_01.txt AC 24 ms 920 KiB
scrambled_02.txt AC 629 ms 804 KiB
scrambled_03.txt AC 559 ms 800 KiB
scrambled_04.txt AC 591 ms 804 KiB
scrambled_05.txt AC 426 ms 812 KiB
scrambled_06.txt AC 456 ms 800 KiB
scrambled_07.txt AC 159 ms 928 KiB
scrambled_08.txt AC 276 ms 800 KiB
scrambled_09.txt AC 514 ms 916 KiB
scrambled_10.txt AC 452 ms 796 KiB
scrambled_11.txt AC 157 ms 928 KiB
scrambled_12.txt AC 435 ms 800 KiB
scrambled_13.txt AC 121 ms 928 KiB
scrambled_14.txt AC 586 ms 26848 KiB
scrambled_15.txt AC 49 ms 2088 KiB
scrambled_16.txt AC 585 ms 26020 KiB
scrambled_17.txt AC 111 ms 5304 KiB
scrambled_18.txt AC 541 ms 24948 KiB
scrambled_19.txt AC 793 ms 64660 KiB
scrambled_20.txt AC 770 ms 57764 KiB
scrambled_21.txt AC 502 ms 38172 KiB
scrambled_22.txt AC 498 ms 37916 KiB
scrambled_23.txt AC 126 ms 9624 KiB
scrambled_24.txt AC 229 ms 18464 KiB