Skip to content

Commit a28e113

Browse files
author
ksh-code
committedMar 7, 2022
yg
1 parent 64f178a commit a28e113

13 files changed

+296
-0
lines changed
 

‎1.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4 4
2+
####
3+
#JF#
4+
#..#
5+
#..#

‎10986

66 KB
Binary file not shown.

‎10986.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <iostream>
2+
#include <map>
3+
using namespace std;
4+
typedef long long ll;
5+
6+
int main()
7+
{
8+
cin.tie(nullptr);
9+
cout.tie(nullptr);
10+
ios::sync_with_stdio(false);
11+
12+
ll N, M; cin >> N >> M;
13+
map<int, int> mp; mp[0] = 1;
14+
ll s = 0;
15+
ll result = 0;
16+
for (int i = 0; i < N; i++) {
17+
ll a; cin >> a; s+= a;
18+
s %= M; result += mp[s]++;
19+
}
20+
21+
cout << result;
22+
return 0;
23+
}

‎1305.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include <map>
3+
using namespace std;
4+
typedef long long ll;
5+
6+
int main()
7+
{
8+
cin.tie(nullptr);
9+
cout.tie(nullptr);
10+
ios::sync_with_stdio(false);
11+
12+
string str; cin >> str;
13+
map<int, int> map;
14+
int result = -1;
15+
int a = 0;
16+
for (int i = 0; i < str.size(); i++) {
17+
str[i] == 'S' ? a+= 2 : a--;
18+
if (map.find(a) == map.end) map[-a] = i;
19+
else result = max(result, i - map[-a]);
20+
}
21+
22+
cout << result;
23+
return 0;
24+
}

‎2041

55.1 KB
Binary file not shown.

‎2041.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
using namespace std;
3+
typedef long long ll;
4+
ll a = 1;
5+
ll c = 1;
6+
ll f() { return (a *= -1) * c++; }
7+
8+
int main(){
9+
cin.tie(nullptr) -> sync_with_stdio(false);
10+
11+
int N, M; cin >> N >> M;
12+
ll arr[N][M]; for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) arr[i][j] = 0;
13+
if (N + M == 2) {
14+
cout << 0;
15+
return 0;
16+
}
17+
arr[0][0] = 2 * N * M;
18+
for (int i = 1; i < M; i++) arr[0][i] = arr[0][i - 1] + f();
19+
if (M % 2 == 0) a *= -1;
20+
21+
for (int i = 1; i < N; i++) {
22+
for (int j = 0; j < M; j++) {
23+
arr[i][j] = arr[i - 1][j] + f();
24+
}
25+
for (int j = 0; j < M - 1; j++) f();
26+
}
27+
28+
for (int i = 0; i < N ; i++) {
29+
for (int j = 0; j < M; j++) {
30+
cout << arr[i][j] << ' ';
31+
}
32+
cout << '\n';
33+
}
34+
return 0;
35+
}

‎24525.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include <map>
3+
using namespace std;
4+
typedef long long ll;
5+
6+
int main()
7+
{
8+
cin.tie(nullptr);
9+
cout.tie(nullptr);
10+
ios::sync_with_stdio(false);
11+
12+
string str; cin >> str;
13+
map<int, int> map;
14+
int result = -1;
15+
int a = 0;
16+
for (int i = 0; i < str.size(); i++) {
17+
str[i] == 'S' ? a+= 2 : a--;
18+
if (map.find(a) == map.end) map[-a] = i;
19+
else result = max(result, i - map[-a]);
20+
}
21+
22+
cout << result;
23+
return 0;
24+
}

‎3673

71.3 KB
Binary file not shown.

‎3673.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
#include <map>
3+
using namespace std;
4+
typedef long long ll;
5+
6+
int main()
7+
{
8+
cin.tie(nullptr);
9+
cout.tie(nullptr);
10+
ios::sync_with_stdio(false);
11+
12+
int T; cin >> T;
13+
while(T--) {
14+
ll N, M; cin >> M >> N;
15+
map<int, int> mp; mp[0] = 1;
16+
ll s = 0;
17+
ll result = 0;
18+
for (int i = 0; i < N; i++) {
19+
ll a; cin >> a; s+= a;
20+
s %= M; result += mp[s]++;
21+
}
22+
cout << result << '\n';
23+
}
24+
return 0;
25+
}

‎4179

94.2 KB
Binary file not shown.

‎4179.cpp

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <iostream>
2+
#include <queue>
3+
#include <string>
4+
using namespace std;
5+
6+
struct Node {
7+
int x, y, count;
8+
};
9+
10+
void solve(){
11+
int N, M; cin >> N >> M;
12+
string map[N]; for (int i = 0; i < N; i++) cin >> map[i];
13+
14+
int start_x = -1, start_y = -1;
15+
16+
int visited[1001][1001] = {0};
17+
int fires[1001][1001];
18+
19+
for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) fires[i][j] = visited[i][j] = 1e9;
20+
21+
queue<Node> queue;
22+
for (int i = 0; i < N; i++) for (int j = 0; j < M; j++)
23+
if (map[i][j] == 'J') start_x = i, start_y = j;
24+
else if (map[i][j] == 'F') {
25+
queue.push({i, j, 0});
26+
fires[i][j] = 0;
27+
}
28+
29+
while (queue.size()) {
30+
auto [x, y, count] = queue.front();
31+
32+
queue.pop();
33+
34+
int xxxx[] = {-1, 0, 1, 0};
35+
int yyyy[] = {0, 1, 0, -1};
36+
37+
for (int i = 0; i < 4; i++) {
38+
int next_x = x + xxxx[i];
39+
int next_y = y + yyyy[i];
40+
int next_count = count + 1;
41+
if (next_x < 0 || next_y < 0 || next_x >= N || next_y >= M || fires[next_x][next_y] <= next_count || map[next_x][next_y] == '#') continue;
42+
43+
fires[next_x][next_y] = next_count;
44+
queue.push({next_x, next_y, next_count});
45+
}
46+
}
47+
visited[start_x][start_y] = 0;
48+
queue.push({start_x, start_y, 0});
49+
50+
while (queue.size()) {
51+
auto [x, y, count] = queue.front();
52+
queue.pop();
53+
54+
if (fires[x][y] <= count) continue;
55+
56+
int xxxx[] = {-1, 0, 1, 0};
57+
int yyyy[] = {0, 1, 0, -1};
58+
59+
for (int i = 0; i < 4; i++) {
60+
int next_x = x + xxxx[i];
61+
int next_y = y + yyyy[i];
62+
int next_count = count + 1;
63+
if (next_x >= N || next_y >= M || next_x < 0 || next_y < 0) {
64+
cout << next_count;
65+
return;
66+
}
67+
if (fires[next_x][next_y] <= next_count || visited[next_x][next_y] != 1e9 || map[next_x][next_y] == '#') continue;
68+
visited[next_x][next_y] = next_count;
69+
queue.push({next_x, next_y, next_count});
70+
}
71+
}
72+
73+
cout << "IMPOSSIBLE";
74+
}
75+
76+
int main(){
77+
cin.tie(0) -> sync_with_stdio(false);
78+
solve();
79+
return 0;
80+
}

‎5427

94.3 KB
Binary file not shown.

‎5427.cpp

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <iostream>
2+
#include <queue>
3+
#include <string>
4+
using namespace std;
5+
6+
struct Node {
7+
int x, y, count;
8+
};
9+
10+
void solve(){
11+
int N, M; cin >> M >> N;
12+
string map[N]; for (int i = 0; i < N; i++) cin >> map[i];
13+
14+
int start_x = -1, start_y = -1;
15+
16+
int visited[1001][1001] = {0};
17+
int fires[1001][1001];
18+
19+
for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) fires[i][j] = visited[i][j] = 1e10;
20+
21+
queue<Node> queue;
22+
for (int i = 0; i < N; i++) for (int j = 0; j < M; j++)
23+
if (map[i][j] == '@') start_x = i, start_y = j;
24+
else if (map[i][j] == '*') {
25+
queue.push({i, j, 0});
26+
fires[i][j] = 0;
27+
}
28+
29+
while (queue.size()) {
30+
auto [x, y, count] = queue.front();
31+
32+
queue.pop();
33+
34+
int xxxx[] = {-1, 0, 1, 0};
35+
int yyyy[] = {0, 1, 0, -1};
36+
37+
for (int i = 0; i < 4; i++) {
38+
int next_x = x + xxxx[i];
39+
int next_y = y + yyyy[i];
40+
int next_count = count + 1;
41+
if (next_x < 0 || next_y < 0 || next_x >= N || next_y >= M || fires[next_x][next_y] <= next_count || map[next_x][next_y] == '#') continue;
42+
43+
fires[next_x][next_y] = next_count;
44+
queue.push({next_x, next_y, next_count});
45+
}
46+
}
47+
visited[start_x][start_y] = 0;
48+
queue.push({start_x, start_y, 0});
49+
50+
while (queue.size()) {
51+
auto [x, y, count] = queue.front();
52+
queue.pop();
53+
54+
if (fires[x][y] <= count) continue;
55+
56+
int xxxx[] = {-1, 0, 1, 0};
57+
int yyyy[] = {0, 1, 0, -1};
58+
59+
for (int i = 0; i < 4; i++) {
60+
int next_x = x + xxxx[i];
61+
int next_y = y + yyyy[i];
62+
int next_count = count + 1;
63+
if (next_x >= N || next_y >= M || next_x < 0 || next_y < 0) {
64+
cout << next_count << '\n';
65+
return;
66+
}
67+
if (fires[next_x][next_y] <= next_count || visited[next_x][next_y] != 1e10 || map[next_x][next_y] == '#') continue;
68+
visited[next_x][next_y] = next_count;
69+
queue.push({next_x, next_y, next_count});
70+
}
71+
}
72+
73+
cout << "IMPOSSIBLE" << '\n';
74+
}
75+
76+
int main(){
77+
cin.tie(0) -> sync_with_stdio(false);
78+
int T; cin >> T; while(T--) solve();
79+
return 0;
80+
}

0 commit comments

Comments
 (0)