Skip to content

Commit 41398fa

Browse files
committed
Recent codeforces
1 parent f9f4f54 commit 41398fa

File tree

4 files changed

+171
-1
lines changed

4 files changed

+171
-1
lines changed

codeforces/7xx/786A.java

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import java.io.*;
2+
import java.util.Arrays;
3+
4+
public class Main {
5+
private StreamTokenizer in;
6+
private PrintWriter out;
7+
8+
private String playground[][];
9+
private int n;
10+
private int sets[][];
11+
12+
int nextInt() throws IOException {
13+
in.nextToken();
14+
return (int)in.nval;
15+
}
16+
17+
public static void main(String[] args) throws IOException {
18+
new Main().run();
19+
}
20+
21+
void run() throws IOException {
22+
in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
23+
out = new PrintWriter(new OutputStreamWriter(System.out));
24+
solve();
25+
out.flush();
26+
}
27+
28+
void simulate_all() {
29+
final String WIN = "Win ";
30+
final String LOSE = "Lose ";
31+
final String LOOP = "Loop ";
32+
boolean changed = true;
33+
int i,j;
34+
35+
Arrays.fill(playground[0], LOOP);
36+
Arrays.fill(playground[1], LOOP);
37+
38+
for (i = 0; i < 2; i++) {
39+
for (int e : sets[i]) {
40+
playground[i][n - e] = WIN;
41+
}
42+
}
43+
while (changed) {
44+
changed = false;
45+
for (i = n - 1; i > 0; i--) {
46+
for (j = 0; j < 2; j++) {
47+
if (playground[j][i] == LOOP) {
48+
boolean win = false;
49+
boolean loop = false;
50+
for (int e : sets[j]) {
51+
int idx = (i + e) % n;
52+
if (playground[1-j][idx] == LOSE) {
53+
win = true;
54+
break;
55+
} else if (playground[1-j][idx] != WIN) {
56+
loop = true;
57+
}
58+
}
59+
60+
if (win) {
61+
changed = true;
62+
playground[j][i] = WIN;
63+
} else if (!loop) {
64+
changed = true;
65+
playground[j][i] = LOSE;
66+
}
67+
}
68+
}
69+
}
70+
}
71+
}
72+
73+
void solve() throws IOException {
74+
int i;
75+
n = nextInt();
76+
int k1 = nextInt();
77+
sets = new int[2][];
78+
sets[0] = new int[k1];
79+
for (i = 0; i < k1; i++) {
80+
sets[0][i] = nextInt();
81+
}
82+
int k2 = nextInt();
83+
sets[1] = new int[k2];
84+
for (i = 0; i < k2; i++) {
85+
sets[1][i] = nextInt();
86+
}
87+
playground = new String[2][];
88+
playground[0] = new String[n];
89+
playground[1] = new String[n];
90+
91+
simulate_all();
92+
93+
StringBuilder b1 = new StringBuilder();
94+
StringBuilder b2 = new StringBuilder();
95+
96+
for (i = 1; i < n; i++) {
97+
b1.append(playground[0][i]);
98+
b2.append(playground[1][i]);
99+
}
100+
101+
out.println(b1.toString());
102+
out.println(b2.toString());
103+
}
104+
}

codeforces/7xx/787A.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
#include <string>
5+
#include <set>
6+
7+
using namespace std;
8+
9+
int a,b,c,d;
10+
bool found;
11+
int answer = -1;
12+
13+
int main() {
14+
cin >> a >> b;
15+
cin >> c >> d;
16+
for (int i = 0; (i <= 100) && (answer == -1); i++) {
17+
for (int j = 0; (j <= 100) && (answer == -1); j++) {
18+
if (b+a*i == d+c*j) {
19+
answer = b+a*i;
20+
}
21+
}
22+
}
23+
cout << answer << endl;
24+
return 0;
25+
}

codeforces/7xx/787B.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
#include <string>
5+
#include <set>
6+
7+
using namespace std;
8+
9+
int i,n,j,m,k,e;
10+
bool answer = false;
11+
12+
int main() {
13+
cin >> n >> m;
14+
bool bad = false;
15+
for (i = 0; i < m; i++) {
16+
set<int> a;
17+
cin >> k;
18+
bad = true;
19+
for (j = 0; j < k; j++) {
20+
cin >> e;
21+
if (bad) {
22+
if (a.find(-e) != a.end()) {
23+
bad = false;
24+
} else {
25+
a.insert(e);
26+
}
27+
}
28+
}
29+
if (bad) {
30+
answer = true;
31+
}
32+
}
33+
if (answer) {
34+
cout << "YES" << endl;
35+
} else {
36+
cout << "NO" << endl;
37+
}
38+
return 0;
39+
}
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.hackerrank;
22

3+
import com.hackerrank.strings.SubstringQueries;
4+
35
import java.io.IOException;
46

57
public class Main {
68
public static void main(String[] args) throws IOException {
7-
// TODO
9+
(new SubstringQueries()).solve();
810
}
911
}

0 commit comments

Comments
 (0)