Submission #440431

# Submission time Handle Problem Language Result Execution time Memory
440431 2021-07-02T09:10:20 Z Abrar_Al_Samit Emacs (COCI20_emacs) C++17
0 / 50
218 ms 179948 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;


#define debug(x) cerr << '[' << (#x) << "] = " << x << '\n';

template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;

void PlayGround() {
    int n, m; cin >> n >> m;
    vector<string>g(n);
    for(string& row : g) cin >> row;
    int ans = 0;

    auto BFS = [&] (int i, int j) {
        queue<pair<int,int>>q;
        q.push({i, j});

        auto valid = [=] (int x, int y) {
            return x>-1 && y>-1 && x<n && y<m && g[x][y]=='*';
        };
        while(!q.empty()) {
            pair<int,int>cur = q.front(); q.pop();
            if(g[cur.first][cur.second]!='*') continue;
            g[cur.first][cur.second] = '.';
            int dx[] {1, -1, 0, 0};
            int dy[] {0, 0, 1, -1};
            for(int k=0; k<4; ++k) {
                int new_i = cur.first + dx[k], new_j = cur.second + dy[k];
                if(valid(new_i, new_j)) 
                    q.push({new_i, new_j});
            }
        }
    };


    for(int i=0; i<n; ++i) {
        for(int j=0; j<m; ++j) {
            if(g[i][j]=='*') {
                BFS(i, j), ++ans;
            }
        }
    }
    cout << ans << '\n';

    #ifndef ONLINE_JUDGE
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
} 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    PlayGround();

    return 0;
}

Compilation message

emacs.cpp: In function 'int main()':
emacs.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 215 ms 179820 KB Output isn't correct
2 Incorrect 215 ms 179864 KB Output isn't correct
3 Incorrect 218 ms 179904 KB Output isn't correct
4 Incorrect 192 ms 179780 KB Output isn't correct
5 Incorrect 205 ms 179872 KB Output isn't correct
6 Incorrect 213 ms 179948 KB Output isn't correct
7 Incorrect 201 ms 179872 KB Output isn't correct
8 Incorrect 211 ms 179872 KB Output isn't correct
9 Incorrect 202 ms 179864 KB Output isn't correct
10 Incorrect 202 ms 179752 KB Output isn't correct