Submission #372215


Source Code Expand

// E.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <cstring>

using namespace std;

typedef long long LL;

LL Max = 0;

struct D;
typedef vector<D*> DPVec;

struct D {
	D *parent;
	D *d[10];
	LL v;
	LL cm;
	D(D *_parent) {
		parent = _parent;
		memset(d, 0, sizeof(d));
		v = 0;
		cm = 0;
	}
};

void add(D &parent) {
	LL cm = 0;
	for (LL i = 0; i < 10; ++i) {
		D *child = parent.d[i];
		if (child) {
			cm = max(cm, child->v + child->cm);
		}
	}
	parent.cm = cm;
	Max = max(Max, parent.v + parent.cm);
	if (parent.parent) {
		add(*parent.parent);
	}
}

void alloc(D &parent, const char *digit, LL value) {
	LL c = *digit++;
	if (c == 0) {
		parent.v += value;
		add(parent);
		return;
	}
	c -= '0';
	D *&next = parent.d[c];
	if (next == NULL) {
		next = new D(&parent);
	}
	alloc(*next, digit, value);
}

int main(int argc, char *argv[]) {
	string s;
	getline(cin, s);
	LL N = atoi(s.c_str());
	D root(NULL);
	for (LL i = 0; i < N; ++i) {
		getline(cin, s);
		stringstream ss(s);
		string a;
		LL b;
		ss >> a >> b;
		reverse(a.begin(), a.end());
		alloc(root, a.c_str(), b);
		cout << Max << endl;
	}
	return 0;
}

Submission Info

Submission Time
Task E - 宝くじ
User greentea
Language C++ (GCC 4.9.2)
Score 200
Code Size 1237 Byte
Status AC
Exec Time 1037 ms
Memory 56616 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 744 KiB
scrambled_01.txt AC 29 ms 752 KiB
scrambled_02.txt AC 788 ms 732 KiB
scrambled_03.txt AC 666 ms 924 KiB
scrambled_04.txt AC 753 ms 800 KiB
scrambled_05.txt AC 458 ms 920 KiB
scrambled_06.txt AC 546 ms 816 KiB
scrambled_07.txt AC 183 ms 812 KiB
scrambled_08.txt AC 301 ms 732 KiB
scrambled_09.txt AC 658 ms 804 KiB
scrambled_10.txt AC 562 ms 804 KiB
scrambled_11.txt AC 198 ms 676 KiB
scrambled_12.txt AC 555 ms 924 KiB
scrambled_13.txt AC 150 ms 796 KiB
scrambled_14.txt AC 766 ms 23584 KiB
scrambled_15.txt AC 58 ms 1960 KiB
scrambled_16.txt AC 762 ms 22800 KiB
scrambled_17.txt AC 138 ms 4640 KiB
scrambled_18.txt AC 705 ms 21880 KiB
scrambled_19.txt AC 958 ms 56616 KiB
scrambled_20.txt AC 1037 ms 50600 KiB
scrambled_21.txt AC 622 ms 33452 KiB
scrambled_22.txt AC 607 ms 33256 KiB
scrambled_23.txt AC 151 ms 8448 KiB
scrambled_24.txt AC 298 ms 16292 KiB