-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
60 lines (57 loc) · 1.17 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
60 lines (57 loc) · 1.17 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
diff --git a/CodeJam/Main.cpp b/examples/2017/Round3/A/Main.cpp
index 2150379..3767cb6 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2017/Round3/A/Main.cpp
@@ -1570,11 +1570,55 @@ void init(){
cin >> T;
}
+str G;
+ll N;
+
void readInput(){
+ cin >> G;
+ N = G.sz;
+}
+
+ll recur(str g){
+ llog("starting recur");
+ lg(g);
+ ll s=0;
+ forn(i, N) s+= (g[i]-'0')*(i+1);
+ if(s>N){
+ ll ans=1;
+ ll rd=N;
+ forn(i, N){
+ ans *= choose<ll>(rd, g[i]-'0');
+ rd -=g[i]-'0';
+ }
+ llog("early break");
+ lg(ans);
+ return ans+1;
+ }
+
+ ll ans=0;
+ str curg="";
+ forn(i, N){
+ forn(j, g[i]-'0') curg += '1'+i;
+ }
+ while(curg.sz < N) curg += '0';
+ sort(all(curg));
+ lg(curg);
+ while(true){
+ if(curg!=g){
+ llog("answer before recur");
+ lg(ans);
+ ans += recur(curg);
+ llog("answer after recur");
+ lg(ans);
+ }
+ if(!next_permutation(all(curg))) break;
+ }
+ return ans + 1;
}
// write to COMM_TYPE result
void calcFunction() {
+ result = recur(G);
}
} // namespace task