File tree 4 files changed +86
-0
lines changed
4 files changed +86
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ MCO 2017 Teleporters
3
+ - Connected component DP
4
+ - See comments in code
5
+ - Complexity: O(N^2)
6
+ */
7
+
8
+ #include < bits/stdc++.h>
9
+ #define FOR (i, x, y ) for (int i = x; i < y; i++)
10
+ typedef long long ll;
11
+ using namespace std ;
12
+
13
+ const ll MOD = 1e9 + 7 ;
14
+
15
+ ll dp[2001 ][2001 ];
16
+
17
+ int main () {
18
+ ios_base::sync_with_stdio (0 );
19
+ cin.tie (0 );
20
+ string S;
21
+ int s, e, n;
22
+ cin >> S >> s >> e;
23
+ n = S.size ();
24
+
25
+ int st = 0 , en = 0 ;
26
+ dp[0 ][0 ] = 1 ;
27
+ FOR (i, 1 , n + 1 ) {
28
+ FOR (j, 1 , i + 1 ) {
29
+ if (i == s) {
30
+ // We move from i to something greater than i
31
+ // That "greater than i" isn't present yet
32
+ if (S[i - 1 ] != ' L' ) dp[i][j] += dp[i - 1 ][j - 1 ];
33
+ // We move from i to something less than i.
34
+ // That "less than i" must already be present
35
+ if (S[i - 1 ] != ' R' ) dp[i][j] += dp[i - 1 ][j];
36
+ } else if (i == e) {
37
+ // We either append i to the end of a component or create an end
38
+ // component. We can do it no matter what S[i - 1] is since we
39
+ // don't go anywhere after this
40
+ dp[i][j] = dp[i - 1 ][j] + dp[i - 1 ][j - 1 ];
41
+ } else {
42
+ // We move to something greater than i. We either create a new
43
+ // component or append to an existing one from the back
44
+ if (S[i - 1 ] != ' L' )
45
+ dp[i][j] += max (0 , j - st - en) * dp[i - 1 ][j - 1 ] +
46
+ (j - en) * dp[i - 1 ][j];
47
+ // We move to something less than i. We either join 2 components
48
+ // or append to an existing one from the front
49
+ if (S[i - 1 ] != ' R' )
50
+ dp[i][j] += j * dp[i - 1 ][j + 1 ] + (j - st) * dp[i - 1 ][j];
51
+ }
52
+ dp[i][j] %= MOD;
53
+ }
54
+ if (i == s) st++;
55
+ if (i == e) en++;
56
+ }
57
+ cout << dp[n][1 ];
58
+ return 0 ;
59
+ }
Original file line number Diff line number Diff line change @@ -52,6 +52,10 @@ This is a collection of the various olympiad problems I have solved
52
52
53
53
[ The Lithuanian Informatics Olympiad] ( http://www.lmio.mii.vu.lt/ )
54
54
55
+ ### MCO
56
+
57
+ The Malaysian Coding Olympiad
58
+
55
59
### NOI.cn
56
60
57
61
[ The National Olympiad in Informatics (China)] ( http://www.noi.cn/ )
Original file line number Diff line number Diff line change
1
+ nums = list (map (int , input ().split ()))
2
+ n = int (input ())
3
+
4
+ sm = sum (nums )
5
+ for i in range (n - len (nums )):
6
+ nums [i % len (nums )], sm = sm , 2 * sm - nums [i % len (nums )]
7
+ print (nums [(n - 1 ) % len (nums )])
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ #define FOR (i, x, y ) for (int i = x; i < y; i++)
3
+ typedef long long ll;
4
+ using namespace std ;
5
+
6
+ int main () {
7
+ ios_base::sync_with_stdio (0 );
8
+ cin.tie (0 );
9
+ int a, b, c;
10
+ cin >> a >> b >> c;
11
+ if (a + b + c != 180 ) return cout << " IMPOSSIBLE" , 0 ;
12
+ if (a == b && b == c) return cout << " EQUILATERAL" , 0 ;
13
+ if (a != b && b != c && c != a) return cout << " SCALENE" , 0 ;
14
+ cout << " ISOSCELES" ;
15
+ return 0 ;
16
+ }
You can’t perform that action at this time.
0 commit comments