-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
69 lines (65 loc) · 1.75 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
69 lines (65 loc) · 1.75 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
diff --git a/CodeJam/Main.cpp b/examples/2020/KS_C/B/Main.cpp
index 2150379..0c38de3 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2020/KS_C/B/Main.cpp
@@ -5,7 +5,7 @@
#define IA_ERROR_CODE -1
#define IA_COMM_LOG //add comment on this line, to deactivate the interactive communication error log
// #define XY_NOTATION //remove commment on this line, to activate xy notation on complex numbers
-#define COMM_TYPE ll
+#define COMM_TYPE str
// The maintained and empty code template can be found at:
// https://github.com/demmerichs/CodeJamTemplate
@@ -1570,11 +1570,55 @@ void init(){
cin >> T;
}
+ll R, C;
+v(str) grid;
+
void readInput(){
+ cin >> R >> C;
+ grid.resize(R);
+ forn(i, R) cin >> grid[i];
}
+d(char, s(char)) required;
+
// write to COMM_TYPE result
void calcFunction() {
+ required.cl;
+ s(char) lets;
+ forn(r, R) forn(c, C) lets.insert(grid[r][c]);
+ foreach(let, lets){
+ required[let];
+ forn(r, R-1){
+ forn(c, C){
+ if(grid[r][c] == let){
+ if(grid[r+1][c] != let){
+ required[let].insert(grid[r+1][c]);
+ }
+ }
+ }
+ }
+ }
+
+ result = "";
+ ll lastsize = required.sz;
+ while(required.sz){
+ lg(required);
+ foreach(req, required){
+ if(req.nd.sz) continue;
+ char nextlet = req.st;
+ result += nextlet;
+ required.erase(nextlet);
+ foreach(r, required){
+ r.nd.erase(nextlet);
+ }
+ break;
+ }
+ if(lastsize == required.sz){
+ result = "-1";
+ break;
+ }
+ lastsize = required.sz;
+ }
}
} // namespace task