-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
133 lines (129 loc) · 3.63 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
133 lines (129 loc) · 3.63 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
diff --git a/CodeJam/Main.cpp b/examples/2020/Qualification/E/Main.cpp
index 2150379..374b086 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2020/Qualification/E/Main.cpp
@@ -1,11 +1,11 @@
-// #define DEFAULT_VAL_MODE //remove comment on this line, to activate default value trigger
+#define DEFAULT_VAL_MODE //remove comment on this line, to activate default value trigger
#define DEFAULT_VAL_TRIGGER result.sz == 0
#define DEFAULT_VAL "IMPOSSIBLE"
// #define IA_MODE //remove comment on this line, to activate interactive problem mode
#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,114 @@ void init(){
cin >> T;
}
+ll N, K;
void readInput(){
+ cin >> N >> K;
+}
+
+v(ll) get_parts(){
+ ll A=-1, B=-1, C=-1;
+ fore(a,1, N){
+ fore(b,1, N){
+ fore(c,1,N){
+ if((a==b || a == c) && b != c) continue;
+ if(N==3 && b==c && a!=b) continue;
+ if((N-2)*a+b+c != K) continue;
+ A = a;
+ B = b;
+ C = c;
+ break;
+ }
+ if(A>=0) break;
+ }
+ if(A>=0) break;
+ }
+ if(A==-1) return v(ll)();
+ v(ll) res(N, A-1);
+ res[0] = B-1;
+ res[1] = C-1;
+ llog("res",res);
+ lassert(accumulate(all(res), 0) == K-N, "sum of parts does not fit");
+ return res;
+}
+
+v(v(ll)) ls;
+
+str visu(){
+ sstr res;
+ forn(i,N){
+ forn(j,N){
+ ll v = ls[i][j];
+ if(v==N || v == -1){
+ // result = "";
+ res << "#";
+ // return;
+ } else
+ res << v;
+ if(j<N-1) res << " ";
+ }
+ if(i<N-1) res << endl;
+ }
+ return "\n"+res.str();
}
// write to COMM_TYPE result
void calcFunction() {
+ v(ll) parts = get_parts();
+ if(parts.sz == 0){
+ result = "";
+ return;
+ }
+ if(K==N+1 || K == N*N - 1){
+ llog(parts);
+ lassert(false, "get_parts did produce something valid what?");
+ result = "";
+ return;
+ }
+ ls.cl;
+ ls = v(v(ll))(N, v(ll)(N, -1));
+ forn(i,N){
+ ls[i][i] = parts[i];
+ }
+
+ forn(r,N){
+ v(v(bool)) col_can_have(N, v(bool)(N, true));
+ forn(i, N){
+ forn(j, N){
+ if(ls[i][j] >= 0)
+ col_can_have[j][ls[i][j]] = false;
+ }
+ }
+ forn(i, N){
+ col_can_have[i][ls[r][r]] = false;
+ col_can_have[r][i] = false;
+ }
+ col_can_have[r][ls[r][r]] = true;
+ v(ll) matched_vals, matched_cols;
+ ll num_matches = maximal_bipartite_matching(col_can_have, matched_vals, matched_cols);
+ lassert(num_matches == N, "how did this happen?");
+ forn(c, N){
+ ls[r][c] = matched_vals[c];
+ }
+ }
+
+ sstr res;
+ result = "POSSIBLE\n";
+ forn(i,N){
+ forn(j,N){
+ // ll v = distance(occ[i][j].bn, find(all(occ[i][j]), -1));
+ ll v = ls[i][j];
+ if(v==N || v == -1){
+ // res << "#";
+ result = "";
+ return;
+ } else
+ res << v+1;
+ if(j<N-1) res << " ";
+ }
+ if(i<N-1) res << endl;
+ }
+ result += res.str();
}
} // namespace task