-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
78 lines (75 loc) · 1.89 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
78 lines (75 loc) · 1.89 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
diff --git a/CodeJam/Main.cpp b/examples/2019/Round1A/C/Main.cpp
index 2150379..14a30cf 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2019/Round1A/C/Main.cpp
@@ -1570,11 +1570,73 @@ void init(){
cin >> T;
}
+ll N;
+v(str) words;
+
void readInput(){
+ cin >> N;
+ words.cl;
+ forn(i,N){
+ str word;
+ cin >> word;
+ reverse(all(word));
+ words.pb(word);
+ }
+ sort(all(words));
+ llog(words);
}
// write to COMM_TYPE result
void calcFunction() {
+ v(ll) matches;
+ forn(i, N-1){
+ ll match = 0;
+ forn(k, words[i].size()){
+ if(words[i][k] == words[i+1][k])
+ ++match;
+ else
+ break;
+ }
+ matches.pb(match);
+ }
+ llog(matches);
+
+ result = 0;
+ forn(_, N/2){
+ ll max_match=0;
+ ll max_idx = -1;
+ forn(i, matches.size()){
+ if(matches[i] > max_match){
+ max_idx = i;
+ max_match=matches[i];
+ }
+ }
+ llog("max match:", max_idx, max_match);
+ if(max_match == 0)
+ break;
+ result += 2;
+ matches.erase(matches.bn + max_idx);
+ forn(k, matches.size()){
+ if(max_idx + k >= matches.size())
+ break;
+ if(matches[max_idx + k] == max_match){
+ matches[max_idx + k] = max_match - 1;
+ } else
+ break;
+ }
+ if(matches.size() == 0)
+ break;
+ if(max_idx == matches.size()){
+ matches.erase(matches.bn + max_idx - 1);
+ } else if(max_idx == 0){
+ matches.erase(matches.bn);
+ } else{
+ ll val = min(matches[max_idx], matches[max_idx - 1]);
+ matches[max_idx - 1] = val;
+ matches.erase(matches.bn + max_idx);
+ }
+ llog(matches);
+ }
}
} // namespace task