# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
251886 |
2020-07-22T20:22:34 Z |
LucaDantas |
Zoo (COCI19_zoo) |
C++17 |
|
45 ms |
3840 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '['; string sep = ""; for (const auto &x : v) os << sep << x, sep = ", "; return os << ']'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename A> ostream& operator<<(ostream &os, const set<A> &s) { os << '{'; string sep = ""; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const map<A, B> &m) { os << '{'; string sep = ""; for (const auto &x : m) os << sep << x.first << " -> " << x.second, sep = ", "; return os << '}'; }
#ifdef MY_DEBUG_FLAG
void debug() { cerr << '\n'; }
template<typename Ini, typename... Fim> void debug(Ini I, Fim... F) { cerr << I; if(sizeof...(F)) cerr << ", "; debug(F...); }
#define db(...) cerr << "DEBUG (" << #__VA_ARGS__ << ") == ", debug(__VA_ARGS__)
#else
#define db(...)
#endif
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr)
#define sz(a) ((int)(a).size())
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define dec(i,n,a) for(int i=(n); i>=(a); i--)
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
constexpr int inf = 0x3f3f3f3f;
constexpr int maxn = 1e3 + 10;
constexpr int mod = 1000000007;
char grid[maxn][maxn];
bool mark[maxn][maxn];
int ans, r, c;
queue<pii> q;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
void dfs(int x, int y) {
mark[x][y] = 1;
rep(cnt,0,4) {
int i = x+dx[cnt], j = y+dy[cnt];
if(i >= r || i < 0 || j >= c || j < 0 || mark[i][j]) continue; // pos invalid
if(grid[i][j] == grid[x][y]) dfs(i, j);
else if(grid[i][j] != '*') {
// we know it's the opposite type
q.push({i, j});
}
}
}
int main() {
clr(grid, '*');
scanf("%d %d", &r, &c);
rep(i,0,r) scanf(" %s", grid[i]);
#ifdef MY_DEBUG_FLAG
rep(i,0,r) {
rep(j,0,c)
printf("%c", grid[i][j]);
printf("\n");
}
printf("\n");
#endif
q.push({0,0});
char last = '*';
while(q.size()) {
pii u = q.front(); q.pop();
if(mark[u.ff][u.ss]) continue;
db(u);
if(grid[u.ff][u.ss] != last) ans++, last = grid[u.ff][u.ss];
dfs(u.ff, u.ss);
#ifdef MY_DEBUG_FLAG
rep(i,0,r) {
rep(j,0,c)
printf("%d", mark[i][j]);
printf("\n");
}
printf("\n");
#endif
}
printf("%d\n", ans);
}
Compilation message
zoo.cpp: In function 'int main()':
zoo.cpp:62:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &r, &c);
~~~~~^~~~~~~~~~~~~~~~~
zoo.cpp:63:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
rep(i,0,r) scanf(" %s", grid[i]);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1280 KB |
Output is correct |
2 |
Correct |
1 ms |
1280 KB |
Output is correct |
3 |
Correct |
1 ms |
1408 KB |
Output is correct |
4 |
Correct |
2 ms |
1408 KB |
Output is correct |
5 |
Correct |
2 ms |
1536 KB |
Output is correct |
6 |
Correct |
1 ms |
1536 KB |
Output is correct |
7 |
Correct |
2 ms |
1536 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
2 ms |
1408 KB |
Output is correct |
10 |
Correct |
1 ms |
1408 KB |
Output is correct |
11 |
Correct |
2 ms |
1408 KB |
Output is correct |
12 |
Correct |
2 ms |
1408 KB |
Output is correct |
13 |
Correct |
1 ms |
1408 KB |
Output is correct |
14 |
Correct |
1 ms |
1408 KB |
Output is correct |
15 |
Correct |
2 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1280 KB |
Output is correct |
2 |
Correct |
1 ms |
1280 KB |
Output is correct |
3 |
Correct |
1 ms |
1408 KB |
Output is correct |
4 |
Correct |
2 ms |
1408 KB |
Output is correct |
5 |
Correct |
2 ms |
1536 KB |
Output is correct |
6 |
Correct |
1 ms |
1536 KB |
Output is correct |
7 |
Correct |
2 ms |
1536 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
2 ms |
1408 KB |
Output is correct |
10 |
Correct |
1 ms |
1408 KB |
Output is correct |
11 |
Correct |
2 ms |
1408 KB |
Output is correct |
12 |
Correct |
2 ms |
1408 KB |
Output is correct |
13 |
Correct |
1 ms |
1408 KB |
Output is correct |
14 |
Correct |
1 ms |
1408 KB |
Output is correct |
15 |
Correct |
2 ms |
1408 KB |
Output is correct |
16 |
Correct |
9 ms |
3840 KB |
Output is correct |
17 |
Correct |
11 ms |
3584 KB |
Output is correct |
18 |
Correct |
11 ms |
3712 KB |
Output is correct |
19 |
Correct |
11 ms |
3712 KB |
Output is correct |
20 |
Correct |
9 ms |
3840 KB |
Output is correct |
21 |
Correct |
39 ms |
3328 KB |
Output is correct |
22 |
Correct |
40 ms |
3328 KB |
Output is correct |
23 |
Correct |
40 ms |
3404 KB |
Output is correct |
24 |
Correct |
43 ms |
3480 KB |
Output is correct |
25 |
Correct |
44 ms |
3456 KB |
Output is correct |
26 |
Correct |
44 ms |
3328 KB |
Output is correct |
27 |
Correct |
42 ms |
3328 KB |
Output is correct |
28 |
Correct |
43 ms |
3372 KB |
Output is correct |
29 |
Correct |
45 ms |
3456 KB |
Output is correct |
30 |
Correct |
44 ms |
3328 KB |
Output is correct |