# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
824489 |
2023-08-14T06:53:45 Z |
반딧불(#10358) |
Sirtet (CCO19_day1problem2) |
C++17 |
|
187 ms |
72972 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int xx[]={0, 1, 0, -1}, yy[]={1, 0, -1, 0};
int n, m;
int board[1000002], ccnt;
inline int get(int x, int y){
return (x-1)*m+y;
}
void dfs(int x, int y, int c){
board[get(x, y)] = c;
//printf("%d %d %d\n", x, y, c);
for(int d=0; d<4; d++){
int tx = x+xx[d], ty=y+yy[d];
if(tx<1 || tx>n || ty<1 || ty>m || board[get(tx, ty)] != -1) continue;
dfs(tx, ty, c);
}
}
vector<pair<int, int> > link[1000002]; /// x번 집합이 k칸 내려갔을 때 y번 집합이 k+d칸까지 내려갈 수 있다면 (y, d) 삽입
int dist[1000002];
bool visited[1000002];
int ans[1000002];
struct dat{
int x, d;
dat(){}
dat(int x, int d): x(x), d(d){}
bool operator<(const dat &r)const{
return d>r.d;
}
};
int main(){
scanf("%d %d", &n, &m);
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
char c;
scanf(" %c", &c);
if(c=='#') board[get(i, j)] = -1;
}
}
for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) if(board[get(i, j)] == -1) dfs(i, j, ++ccnt);
//for(int i=1; i<=n; i++){
// for(int j=1; j<=m; j++){
// printf("%d", board[get(i, j)]);
// }
// puts("");
//}
for(int j=1; j<=m; j++){
int lastI = n+1, lastC = 0;
for(int i=n; i>=1; i--){
if(!board[get(i, j)]) continue;
if(lastC == board[get(i, j)]) lastI = i;
else{
link[lastC].push_back(make_pair(board[get(i, j)], lastI-i-1));
lastC = board[get(i, j)], lastI = i;
}
}
}
priority_queue<dat> pq;
pq.push(dat(0, 0));
while(!pq.empty()){
dat tmp = pq.top(); pq.pop();
if(visited[tmp.x]) continue;
visited[tmp.x] = 1;
dist[tmp.x] = tmp.d;
//printf("dijkstra %d - %d\n", tmp.x, tmp.d);
for(auto p: link[tmp.x]){
pq.push(dat(p.first, tmp.d + p.second));
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(!board[get(i, j)]) continue;
int c = board[get(i, j)];
ans[get(i+dist[c], j)] = c;
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++) printf("%c", ans[get(i, j)] ? '#' : '.');
puts("");
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:45:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf(" %c", &c);
| ~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23776 KB |
Output is correct |
2 |
Correct |
14 ms |
23792 KB |
Output is correct |
3 |
Correct |
13 ms |
23816 KB |
Output is correct |
4 |
Correct |
10 ms |
23764 KB |
Output is correct |
5 |
Correct |
10 ms |
23764 KB |
Output is correct |
6 |
Correct |
10 ms |
23808 KB |
Output is correct |
7 |
Correct |
10 ms |
23752 KB |
Output is correct |
8 |
Correct |
13 ms |
23764 KB |
Output is correct |
9 |
Correct |
10 ms |
23764 KB |
Output is correct |
10 |
Correct |
10 ms |
23764 KB |
Output is correct |
11 |
Correct |
10 ms |
23764 KB |
Output is correct |
12 |
Correct |
13 ms |
23832 KB |
Output is correct |
13 |
Correct |
10 ms |
23816 KB |
Output is correct |
14 |
Correct |
10 ms |
23764 KB |
Output is correct |
15 |
Correct |
13 ms |
23764 KB |
Output is correct |
16 |
Correct |
14 ms |
23840 KB |
Output is correct |
17 |
Correct |
10 ms |
23764 KB |
Output is correct |
18 |
Correct |
10 ms |
23836 KB |
Output is correct |
19 |
Correct |
10 ms |
23764 KB |
Output is correct |
20 |
Correct |
10 ms |
23804 KB |
Output is correct |
21 |
Correct |
12 ms |
23788 KB |
Output is correct |
22 |
Correct |
14 ms |
23888 KB |
Output is correct |
23 |
Correct |
14 ms |
23712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
34196 KB |
Output is correct |
2 |
Correct |
121 ms |
41804 KB |
Output is correct |
3 |
Correct |
104 ms |
33340 KB |
Output is correct |
4 |
Correct |
103 ms |
32464 KB |
Output is correct |
5 |
Correct |
125 ms |
49268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23776 KB |
Output is correct |
2 |
Correct |
14 ms |
23792 KB |
Output is correct |
3 |
Correct |
13 ms |
23816 KB |
Output is correct |
4 |
Correct |
10 ms |
23764 KB |
Output is correct |
5 |
Correct |
10 ms |
23764 KB |
Output is correct |
6 |
Correct |
10 ms |
23808 KB |
Output is correct |
7 |
Correct |
10 ms |
23752 KB |
Output is correct |
8 |
Correct |
13 ms |
23764 KB |
Output is correct |
9 |
Correct |
10 ms |
23764 KB |
Output is correct |
10 |
Correct |
10 ms |
23764 KB |
Output is correct |
11 |
Correct |
10 ms |
23764 KB |
Output is correct |
12 |
Correct |
13 ms |
23832 KB |
Output is correct |
13 |
Correct |
10 ms |
23816 KB |
Output is correct |
14 |
Correct |
10 ms |
23764 KB |
Output is correct |
15 |
Correct |
13 ms |
23764 KB |
Output is correct |
16 |
Correct |
14 ms |
23840 KB |
Output is correct |
17 |
Correct |
10 ms |
23764 KB |
Output is correct |
18 |
Correct |
10 ms |
23836 KB |
Output is correct |
19 |
Correct |
10 ms |
23764 KB |
Output is correct |
20 |
Correct |
10 ms |
23804 KB |
Output is correct |
21 |
Correct |
12 ms |
23788 KB |
Output is correct |
22 |
Correct |
14 ms |
23888 KB |
Output is correct |
23 |
Correct |
14 ms |
23712 KB |
Output is correct |
24 |
Correct |
109 ms |
34196 KB |
Output is correct |
25 |
Correct |
121 ms |
41804 KB |
Output is correct |
26 |
Correct |
104 ms |
33340 KB |
Output is correct |
27 |
Correct |
103 ms |
32464 KB |
Output is correct |
28 |
Correct |
125 ms |
49268 KB |
Output is correct |
29 |
Correct |
95 ms |
42572 KB |
Output is correct |
30 |
Correct |
126 ms |
46132 KB |
Output is correct |
31 |
Correct |
94 ms |
45376 KB |
Output is correct |
32 |
Correct |
54 ms |
31552 KB |
Output is correct |
33 |
Correct |
106 ms |
47668 KB |
Output is correct |
34 |
Correct |
115 ms |
40112 KB |
Output is correct |
35 |
Correct |
118 ms |
38220 KB |
Output is correct |
36 |
Correct |
95 ms |
33756 KB |
Output is correct |
37 |
Correct |
86 ms |
33992 KB |
Output is correct |
38 |
Correct |
88 ms |
37336 KB |
Output is correct |
39 |
Correct |
83 ms |
32884 KB |
Output is correct |
40 |
Correct |
123 ms |
32396 KB |
Output is correct |
41 |
Correct |
93 ms |
40004 KB |
Output is correct |
42 |
Correct |
127 ms |
48924 KB |
Output is correct |
43 |
Correct |
88 ms |
30916 KB |
Output is correct |
44 |
Correct |
89 ms |
32616 KB |
Output is correct |
45 |
Correct |
84 ms |
29048 KB |
Output is correct |
46 |
Correct |
94 ms |
37684 KB |
Output is correct |
47 |
Correct |
90 ms |
38380 KB |
Output is correct |
48 |
Correct |
97 ms |
31336 KB |
Output is correct |
49 |
Correct |
110 ms |
30912 KB |
Output is correct |
50 |
Correct |
114 ms |
64764 KB |
Output is correct |
51 |
Correct |
99 ms |
31216 KB |
Output is correct |
52 |
Correct |
123 ms |
34020 KB |
Output is correct |
53 |
Correct |
105 ms |
31404 KB |
Output is correct |
54 |
Correct |
135 ms |
37212 KB |
Output is correct |
55 |
Correct |
154 ms |
38284 KB |
Output is correct |
56 |
Correct |
150 ms |
37364 KB |
Output is correct |
57 |
Correct |
112 ms |
30888 KB |
Output is correct |
58 |
Correct |
96 ms |
31712 KB |
Output is correct |
59 |
Correct |
127 ms |
37468 KB |
Output is correct |
60 |
Correct |
104 ms |
32804 KB |
Output is correct |
61 |
Correct |
88 ms |
32368 KB |
Output is correct |
62 |
Correct |
109 ms |
31956 KB |
Output is correct |
63 |
Correct |
138 ms |
72972 KB |
Output is correct |
64 |
Correct |
187 ms |
48048 KB |
Output is correct |
65 |
Correct |
124 ms |
48716 KB |
Output is correct |
66 |
Correct |
156 ms |
48640 KB |
Output is correct |
67 |
Correct |
91 ms |
24928 KB |
Output is correct |
68 |
Correct |
81 ms |
24856 KB |
Output is correct |
69 |
Correct |
98 ms |
35972 KB |
Output is correct |
70 |
Correct |
79 ms |
24768 KB |
Output is correct |