CSES - Datatähti 2020 loppu - Results
Submission details
Task:Aliruudukot
Sender:Pauli Kauro
Submission time:2020-02-09 16:21:18 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.03 s1, 2, 3details
#20.02 s1, 2, 3details
#30.02 s1, 2, 3details
#40.03 s1, 2, 3details
#50.02 s1, 2, 3details
#60.02 s1, 2, 3details
#70.02 s1, 2, 3details
#80.02 s1, 2, 3details
#90.02 s1, 2, 3details
#100.02 s1, 2, 3details
#110.02 s1, 2, 3details
#120.02 s1, 2, 3details
#130.03 s1, 2, 3details
#140.02 s1, 2, 3details
#150.02 s1, 2, 3details
#160.03 s1, 2, 3details
#170.02 s1, 2, 3details
#180.02 s1, 2, 3details
#190.02 s1, 2, 3details
#20ACCEPTED0.03 s1, 2, 3details
#21ACCEPTED0.02 s1, 2, 3details
#22ACCEPTED0.03 s1, 2, 3details
#23ACCEPTED0.02 s1, 2, 3details
#240.03 s1, 2, 3details
#250.03 s1, 2, 3details
#260.03 s1, 2, 3details
#27ACCEPTED0.03 s2, 3details
#280.04 s2, 3details
#290.04 s2, 3details
#300.05 s2, 3details
#310.05 s2, 3details
#320.04 s2, 3details
#330.06 s2, 3details
#340.05 s2, 3details
#350.06 s2, 3details
#360.06 s2, 3details
#370.06 s2, 3details
#380.06 s2, 3details
#390.05 s2, 3details
#400.05 s2, 3details
#410.05 s2, 3details
#420.06 s2, 3details
#430.06 s2, 3details
#440.07 s2, 3details
#450.07 s2, 3details
#460.06 s2, 3details
#470.06 s2, 3details
#480.06 s2, 3details
#490.06 s2, 3details
#500.07 s2, 3details
#510.07 s2, 3details
#520.06 s2, 3details
#530.48 s3details
#540.47 s3details
#55--3details
#56--3details
#57--3details
#58--3details
#59--3details
#60--3details
#61--3details
#62--3details
#63--3details
#64--3details
#65--3details
#66--3details
#67--3details
#68--3details
#69--3details
#70--3details
#71--3details
#72--3details
#73--3details
#74--3details
#75--3details
#76--3details
#77--3details
#78--3details

Code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int N = 1000, M = 1000;

int n, m;

char r[N][M];
// y, x

int memo[N][M];
using hash_t = string;
//ll hashh[N][M];
hash_t hashh[N][M];

/*static inline ll mkhash(ll prev, char c) {
	return (prev << 5) + c;
}
*/
static inline hash_t mkhash(hash_t prev, char c) {
	return prev + c;
}

static inline hash_t inithash(char c) {
	return "" + c;
}

int main() {
	cin >> n >> m;
	for (int y = 0; y < n; y++) {
		for (int x = 0; x < m; x++) {
			cin >> r[y][x];
			//r[y][x] -= 'A';
		}
	}
	memo[0][0] = 1;
	hashh[0][0] = inithash(r[0][0]);

	// ylareuna
	for (int x = 1; x < m; x++) {
		memo[0][x] = x + 1;
		hashh[0][x] = mkhash(hashh[0][x - 1], r[0][x]);
	}
	// vasen laita
	for (int y = 1; y < n; y++) {
		memo[y][0] = y + 1;
		hashh[y][0] = mkhash(hashh[y - 1][0], r[y][0]);
	}

	for (int y = 1; y < n; y++) {
		for (int x = 1; x < m; x++) {
			ll nextmemo = 1;
			hash_t nexthash = inithash(r[y][x]);
			// ruutuun paasee kahta kautta: ylapuolelta, vasemmalta
			if (hashh[y - 1][x] == hashh[y][x - 1]) {
				// voidaan laajentaa ruudusta (y - 1, x - 1)
				// edellinen + vaaka + pysty + 1
				ll nyt = memo[y - 1][x - 1] + x + y + 1;
				// TODO: monta mahdollisuutta?
				nextmemo = nyt;
				nexthash = mkhash(hashh[y][x - 1], r[y][x]);
			}
			// ylhaalta
			if (y + 1 > nextmemo) {
				// nextmemo = memo[y - 1][x] + 1;
				nextmemo = y + 1;
				// nexthash = mkhash(hashh[y - 1][x], r[y][x]);
				nexthash = inithash(r[0][x]);
				for (ll i = 1; i <= y; i++) nexthash = mkhash(nexthash, r[i][x]);
			}
			// vasemmalta
			if (x + 1 > nextmemo) {
				// nextmemo = memo[y][x - 1] + 1;
				nextmemo = x + 1;
				// nexthash = mkhash(hashh[y][x - 1], r[y][x]);
				nexthash = inithash(r[y][0]);
				for (ll i = 1; i <= x; i++) nexthash = mkhash(nexthash, r[y][i]);
			}
			memo[y][x] = nextmemo;
			hashh[y][x] = nexthash;
		}
	}

	ll ans = 1;
	for (int y = 0; y < n; y++) {
		for (int x = 0; x < m; x++) {
			//cout << y << "," << x << ": " << memo[y][x] << endl;
			ans = max(ans, static_cast<ll>(memo[y][x]));
		}
	}
	cout << ans << endl;
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
10 10
ABCDEFGHIJ
BCDEFGHIJK
CDEFGHIJKL
DEFGHIJKLM
...

correct output
100

user output
100

Test 2

Group: 1, 2, 3

Verdict:

input
10 10
ABCDEFGHPJ
BCDEFGHIJK
CDEFGHIJKL
DTFGHIJKLM
...

correct output
72

user output
80

Test 3

Group: 1, 2, 3

Verdict:

input
10 10
ABCDEFGHIJ
BCDEFGHIJK
CDEFGHIJKL
PEFGHJJKLM
...

correct output
40

user output
52

Test 4

Group: 1, 2, 3

Verdict:

input
10 10
ABCDEFGHIJ
BCDEFGHIJK
CDEFGNIJKY
DEFGHIJKLM
...

correct output
30

user output
58

Test 5

Group: 1, 2, 3

Verdict:

input
10 10
ABCDEFGHIJ
BCDEFGJIJK
CDEFOHIJKL
DEFGHIJKLM
...

correct output
24

user output
20

Test 6

Group: 1, 2, 3

Verdict:

input
10 10
SBCDEFGHIJ
BCDEFGCIJK
CXEFGHIJKL
DEDGHIKKWM
...

correct output
20

user output
24

Test 7

Group: 1, 2, 3

Verdict:

input
10 10
ABFDEFGHIJ
BCDEFGHOJK
CDEFGNXJKL
DPFGHIJKLM
...

correct output
42

user output
66

Test 8

Group: 1, 2, 3

Verdict:

input
10 10
ABQDEFGHIA
BCDEFGHIHK
CDEFGHIJKL
DEFGHIAKGM
...

correct output
30

user output
17

Test 9

Group: 1, 2, 3

Verdict:

input
10 10
AYCDEFGHIJ
BCDEFGHVJK
CDEFGQIJKC
DEFGHKPKLM
...

correct output
32

user output
28

Test 10

Group: 1, 2, 3

Verdict:

input
10 10
ABCREAGHQJ
NCDEFGHIJK
CDEFXHIUKL
DEFGHIJKLM
...

correct output
20

user output
14

Test 11

Group: 1, 2, 3

Verdict:

input
10 10
ABCDEFGSBJ
BRDEFGHIJK
CYEFGPIPKL
DEFGHIJASM
...

correct output
16

user output
17

Test 12

Group: 1, 2, 3

Verdict:

input
10 10
ABCBGFGHIJ
BCDEFOHILK
CDEFGUIJKL
DEFGHIJKLT
...

correct output
20

user output
18

Test 13

Group: 1, 2, 3

Verdict:

input
10 10
ABCFEFGHIJ
BCDQFGYIJK
COEFGHIZKL
JELGHIJZLM
...

correct output
20

user output
24

Test 14

Group: 1, 2, 3

Verdict:

input
10 10
ABCPNFGCIJ
ICRQFGFIJK
PDEFGHIJKL
DQFGHIJKVM
...

correct output
21

user output
19

Test 15

Group: 1, 2, 3

Verdict:

input
10 10
AMCJEFEIXJ
BYDEFGHIBI
CDEFGHIDKL
DEFQXQJKYM
...

correct output
15

user output
10

Test 16

Group: 1, 2, 3

Verdict:

input
10 10
XBCDUFGHNJ
BCDEFGHIJK
BDEFGHIJKL
DEKGHIJKLM
...

correct output
24

user output
10

Test 17

Group: 1, 2, 3

Verdict:

input
10 10
ARCDEFMHIJ
BCDEHGSNJK
CVEFGHIJZL
DEZRHIJSDM
...

correct output
16

user output
10

Test 18

Group: 1, 2, 3

Verdict:

input
10 10
AGCDEOGHIJ
BADEJGHIJP
CDURGHIJKL
VELGXIJKLM
...

correct output
32

user output
10

Test 19

Group: 1, 2, 3

Verdict:

input
10 10
ABCKEFGRIJ
RWBECVHGIK
COEFKHIJKL
DEVZHXBKLM
...

correct output
12

user output
10

Test 20

Group: 1, 2, 3

Verdict: ACCEPTED

input
10 10
ABDDQFGFIJ
BXJEFKHIKK
TDSFVHILKL
HEFOHKQPLM
...

correct output
10

user output
10

Test 21

Group: 1, 2, 3

Verdict: ACCEPTED

input
10 10
LBCDEFGUIJ
BCDEFGHIJK
CDZJGBIJKL
DHFGHNJXLM
...

correct output
14

user output
14

Test 22

Group: 1, 2, 3

Verdict: ACCEPTED

input
10 10
BJCDEFGHIO
MLHEDOHIJH
CDEFWWIJKL
DEFNHIEKLM
...

correct output
10

user output
10

Test 23

Group: 1, 2, 3

Verdict: ACCEPTED

input
10 10
ABCDEFMHIJ
WCDEFLHIJK
CDXACHIJEL
DENPVIJVAU
...

correct output
10

user output
10

Test 24

Group: 1, 2, 3

Verdict:

input
10 10
YBKDEFMRJF
BRDEFAHIDK
PDOFGUHJKL
NEFGHQJTHM
...

correct output
12

user output
10

Test 25

Group: 1, 2, 3

Verdict:

input
10 10
OBODEFGRBJ
FCDEFGHIQK
CDAFGHIJKY
DEFKHIHKLM
...

correct output
12

user output
15

Test 26

Group: 1, 2, 3

Verdict:

input
10 10
LBQDEPGHIJ
BCOEODHIJK
CHEUGQIJKL
EEHGQIJBWM
...

correct output
12

user output
10

Test 27

Group: 2, 3

Verdict: ACCEPTED

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
10000

user output
10000

Test 28

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
6000

user output
7648

Test 29

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
3600

user output
5840

Test 30

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
5700

user output
5460

Test 31

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
4400

user output
5030

Test 32

Group: 2, 3

Verdict:

input
100 100
ABCQEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
3430

user output
7450

Test 33

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
3871

user output
5420

Test 34

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
3036

user output
4888

Test 35

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
3116

user output
4852

Test 36

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
2142

user output
3309

Test 37

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMAOPQRSTUVWXYZABCD...

correct output
1920

user output
3178

Test 38

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
2205

user output
3626

Test 39

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIFKLMNOPQRSTUVWXYZABCD...

correct output
2520

user output
3120

Test 40

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
2655

user output
3753

Test 41

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
2244

user output
3496

Test 42

Group: 2, 3

Verdict:

input
100 100
ABCDEUGHIJKLMNOPQRSTUVWXYZABCD...

correct output
1872

user output
3358

Test 43

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
2278

user output
2376

Test 44

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
1500

user output
3028

Test 45

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
1890

user output
4055

Test 46

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
1734

user output
3521

Test 47

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
2448

user output
5045

Test 48

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHAJKLMNOPQRSTUVWXYZABCD...

correct output
1248

user output
3330

Test 49

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
1953

user output
3590

Test 50

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUNWXYZABCD...

correct output
1216

user output
2595

Test 51

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
1344

user output
3126

Test 52

Group: 2, 3

Verdict:

input
100 100
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
1422

user output
2518

Test 53

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
1000000

user output
(empty)

Test 54

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
887000

user output
(empty)

Test 55

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
553532

user output
(empty)

Test 56

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
456765

user output
(empty)

Test 57

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
510000

user output
(empty)

Test 58

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
455413

user output
(empty)

Test 59

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
287300

user output
(empty)

Test 60

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
326616

user output
(empty)

Test 61

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
396240

user output
(empty)

Test 62

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
311022

user output
(empty)

Test 63

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
374946

user output
(empty)

Test 64

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
342454

user output
(empty)

Test 65

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
271911

user output
(empty)

Test 66

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
279000

user output
(empty)

Test 67

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
208096

user output
(empty)

Test 68

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
170914

user output
(empty)

Test 69

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
261508

user output
(empty)

Test 70

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
299757

user output
(empty)

Test 71

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
195250

user output
(empty)

Test 72

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
160638

user output
(empty)

Test 73

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
197340

user output
(empty)

Test 74

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
212000

user output
(empty)

Test 75

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
177184

user output
(empty)

Test 76

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
132534

user output
(empty)

Test 77

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
143868

user output
(empty)

Test 78

Group: 3

Verdict:

input
1000 1000
ABCDEFGHIJKLMNOPQRSTUVWXYZABCD...

correct output
114480

user output
(empty)