Submission #2712842


Source Code Expand

#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); ++i)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

struct node {
  node *ch[10];
  ll val;
  ll ma;
  ll lazy;
  node() {
    val = 0;
    ma = 0;
    lazy = 0;
    REP(i, 0, 10) ch[i] = NULL;
  }
  void add(const string &a, int pos, ll v) {
    if (pos >= (int) a.size()) {
      lazy += v;
      ma = ::max(val, ma);
      return;
    }
    // propagate
    int idx = a[pos] - '0';
    if (lazy != 0) {
      REP(idx, 0, 10) {
	if (ch[idx] == NULL) ch[idx] = new node;
      }
      REP(i, 0, 10) {
	if (ch[i]) {
	  ch[i]->lazy += lazy;
	}
      }
    }
    ma += lazy;
    val += lazy;
    lazy = 0;
    if (ch[idx] == NULL) ch[idx] = new node;
    ch[idx]->add(a, pos + 1, v);
    ma = ::max(ma, ch[idx]->max());
  }
  ll max(void) const {
    return lazy + ma;
  }
  void debug(string s = "") const {
    cerr << "[" << s << "]:" << val << "(m:" << ma << ") (l:" << lazy << ")"
	 << endl;
    REP(i, 0, 10) {
      if (ch[i]) {
	ch[i]->debug(s + (char)('0' + i));
      }
    }
  }
} root;

int main(void) {
  int n;
  cin >> n;
  REP(i, 0, n) {
    string a;
    ll b;
    cin >> a >> b;
    reverse(a.begin(), a.end());
    root.add(a, 0, b);
    cout << root.max() << endl;
    // root.debug();
  }
}

Submission Info

Submission Time
Task E - 宝くじ
User kobae964
Language C++14 (GCC 5.4.1)
Score 200
Code Size 1516 Byte
Status AC
Exec Time 455 ms
Memory 174976 KB

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 1 ms 256 KB
scrambled_01.txt AC 1 ms 256 KB
scrambled_02.txt AC 311 ms 1664 KB
scrambled_03.txt AC 273 ms 1536 KB
scrambled_04.txt AC 309 ms 1664 KB
scrambled_05.txt AC 206 ms 1152 KB
scrambled_06.txt AC 240 ms 1280 KB
scrambled_07.txt AC 78 ms 512 KB
scrambled_08.txt AC 134 ms 768 KB
scrambled_09.txt AC 287 ms 1664 KB
scrambled_10.txt AC 245 ms 1408 KB
scrambled_11.txt AC 78 ms 640 KB
scrambled_12.txt AC 238 ms 1408 KB
scrambled_13.txt AC 58 ms 512 KB
scrambled_14.txt AC 455 ms 174976 KB
scrambled_15.txt AC 22 ms 10240 KB
scrambled_16.txt AC 439 ms 169856 KB
scrambled_17.txt AC 73 ms 32128 KB
scrambled_18.txt AC 416 ms 162816 KB
scrambled_19.txt AC 377 ms 57088 KB
scrambled_20.txt AC 385 ms 53888 KB
scrambled_21.txt AC 239 ms 33664 KB
scrambled_22.txt AC 243 ms 33408 KB
scrambled_23.txt AC 50 ms 8064 KB
scrambled_24.txt AC 106 ms 16000 KB