東京大学プログラミングコンテスト2014

Submission #6896526

Source codeソースコード

#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) v.erase(unique(ALL(v)), v.end())
#define bit(i) (1LL<<i)
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

template <int N> class Trie{
public:
  int table[N];
  
  struct node{
    LLI val;
    LLI sum = 0;
    
    node *ch[N] = {};
    
    node(LLI val): val(val){}
    node(): val(0){}
  };

  Trie(const string &s){
    REP(i,(int)s.size()){
      table[(int)s[i]] = i;
    }
  }

  node *root = nullptr;

  node* insert(node *t, const string &s, int val, int i){
    if(!t) t = new node();

    if(i >= (int)s.size()){
      t->val = val;

      
      LLI x = 0;
      REP(i,N){
        if(t->ch[i]) chmax(x, t->ch[i]->sum);
      }
      t->sum = x+t->val;

      return t;
    }

    int c = table[(int)s[i]];
    t->ch[c] = insert(t->ch[c], s, val, i+1);

    LLI x = 0;
    REP(i,N){
      if(t->ch[i]) chmax(x, t->ch[i]->sum);
    }
    t->sum = x+t->val;

    return t;
  }
  
  void insert(const string &s, int val){
    root = insert(root, s, val, 0);
  }

  node* find(node *t, char c){
    if(!t) return t;
    return t->ch[table[(int)c]];
  }

  node* find(const string &s){
    node *t = root;
    int i = 0;
    
    while(t and i<(int)s.size()){
      t = find(t,s[i]);
      if(!t) return nullptr;
      ++i;
    }
 
    return t;
  }
};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  while(cin >> N){

    Trie<10> trie("0123456789");

    REP(i,N){
      string a; cin >> a;
      int b; cin >> b;

      reverse(ALL(a));

      trie.insert(a,b);

      cout << trie.root->sum << endl;
    }
  }
  
  return 0;
}

Submission

Task問題 E - 宝くじ
User nameユーザ名 Haar
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 3170 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
All 0 / 200 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
scrambled_00.txt AC 1 ms 256 KB
scrambled_01.txt AC 1 ms 256 KB
scrambled_02.txt WA
scrambled_03.txt WA
scrambled_04.txt WA
scrambled_05.txt WA
scrambled_06.txt WA
scrambled_07.txt WA
scrambled_08.txt WA
scrambled_09.txt WA
scrambled_10.txt WA
scrambled_11.txt WA
scrambled_12.txt WA
scrambled_13.txt WA
scrambled_14.txt WA
scrambled_15.txt WA
scrambled_16.txt WA
scrambled_17.txt WA
scrambled_18.txt WA
scrambled_19.txt AC 298 ms 57088 KB
scrambled_20.txt AC 321 ms 51200 KB
scrambled_21.txt AC 198 ms 33664 KB
scrambled_22.txt AC 197 ms 33408 KB
scrambled_23.txt AC 44 ms 8192 KB
scrambled_24.txt AC 88 ms 16128 KB