Submission #1260395

#TimeUsernameProblemLanguageResultExecution timeMemory
1260395tminhEmacs (COCI20_emacs)C++20
50 / 50
0 ms328 KiB
#include "bits/stdc++.h" using namespace std; #define task "" #define ll long long #define endl '\n' #define fi first #define se second #define vall(a) (a).begin(), (a).end() #define sze(a) (int)a.size() #define pii pair<int, int> #define pll pair<ll, ll> #define ep emplace_back #define pb push_back #define pf push_front const ll mod = 1e9 + 7; const int N = 105; const ll oo = 1e18; bool START; int n, m; char a[N][N]; ll ans = 0; bool vis[N][N]; int hx[] = {0, 0, -1, 1}; int hy[] = {1, -1, 0, 0}; int bfs(int u, int v) { queue<pii> q; if (vis[u][v]) return 0; q.push(make_pair(u, v)); while(!q.empty()) { auto[x, y] = q.front(); q.pop(); for (int i = 0; i < 4; ++i) { int xx = hx[i] + x; int yy = hy[i] + y; if (xx < 1 || xx > n || yy < 1 || yy > m || vis[xx][yy] || a[xx][yy] == '.') continue; vis[xx][yy] = true; q.push(make_pair(xx, yy)); } } return 1; } inline void solve() { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) if (a[i][j] == '*') ans += bfs(i, j); } cout << ans; } inline void input() { cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) cin >> a[i][j]; } return solve(); } bool END; int main() { if(fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); input(); cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl; cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n"; return 0; }

Compilation message (stderr)

emacs.cpp: In function 'int main()':
emacs.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
emacs.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...