aboutsummaryrefslogtreecommitdiff
path: root/2023/15/15b.c
blob: bfdafe49f4b4b811116a9b0c5a5757188bfe4669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <inttypes.h>
#include <stdio.h>

#define N 100000

char *b, line[N];
int64_t c, l, s, n[256], box[256][N];

int main() {
	fgets(line, N, stdin);

	for (b = line, c = 0; *b != '\n'; b++) {
		switch (*b) {
		case ',':
			c = l = 0;
			break;
		case '=':
			int64_t i;
			for (i = 0; i < n[c]; i++)
				if (box[c][i] / 10 == l)
					break;
			if (i == n[c]) n[c]++;
			box[c][i] = l * 10 + (int)(*(++b)-'0');
			break;
		case '-':
			for (int64_t i = 0; i < n[c]; i++) {
				if (box[c][i] / 10 == l) {
					for (int j = i+1; j < n[c]; j++)
						box[c][j-1] = box[c][j];
					n[c]--;
				}
			}
			break;
		default:
			c = (c + (int)*b) * 17 % 256;
			l = l*256 + (int)*b;
			break;
		}
	}

	for (int64_t i = 0; i < 256; i++)
		for (int64_t j = 0; j < n[i]; j++)
			s += (i+1) * (j+1) * (box[i][j]%10);

	printf("%" PRId64 "\n", s);
	return 0;
}

Generated with cgit - Back to sebastiano.tronto.net