Submission #1221598

#TimeUsernameProblemLanguageResultExecution timeMemory
1221598khomeT-Covering (eJOI19_covering)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define intl long long

void solve(){
    int n, m; cin >> n >> m;
    vector<vector<int>> els(n, vector<int>(m));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> els[i][j];
        }
    }
    
    int k; cin >> k;
    vector<pair<int, int>> xs(k);
    for (int i = 0; i < k; i ++){
        int x, y; cin >> x >> y;
        xs[i] = {x, y};
    }
    sort(xs.begin(), xs.end());
    bool so = true;
    vector<set<pair<int, int>>> components;
    
    for (auto& pr : xs){
        int x = pr.first, y = pr.second;
        bool est = false;

        for (set<pair<int, int>> &st : components){
            if (st.find({x-1, y-1}) != st.end()) est = true;
            
            else if (st.find({x+1, y+1}) != st.end()) est = true;
            
            else if (st.find({x-1, y}) != st.end()) est = true;

            else if (st.find({x, y-1}) != st.end()) est = true;

            else if (st.find({x+1, y}) != st.end()) est = true;

            else if (st.find({x, y+1}) != st.end()) est = true;

            else if (st.find({x, y+2}) != st.end()) est = true;

            else if (st.find({x, y-2}) != st.end()) est = true;

            else if (st.find({x+2, y}) != st.end()) est = true;

            else if (st.find({x-2, y}) != st.end()) est = true;

            if (est) {
                st.insert({x, y});
                break;
            }
        }

        if (!est) {
            components.push_back({{x, y}});
        }
    }
    
    int ans = 0;
    for (auto smth : components){
        set<vector<int>> sosedi;
        int cnt = 0;
        for (pair<int, int> pr : smth) {
            int x = pr.first, y = pr.second;
            cnt += els[x][y];

            if (x-1 >= 0 && sosedi.find({els[x-1][y], x-1, y}) == sosedi.end()) {
                sosedi.insert({els[x-1][y], x-1, y}); 
                cnt += els[x-1][y];
            }

            if (x+1 < n && sosedi.find({els[x+1][y], x+1, y}) == sosedi.end()) {
                sosedi.insert({els[x+1][y], x+1, y}); 
                cnt += els[x+1][y];
            }

            if (y-1 >= 0 && sosedi.find({els[x][y-1], x, y-1}) == sosedi.end()) {
                sosedi.insert({els[x][y-1], x, y-1}); 
                cnt += els[x][y-1];
            }

            if (y+1 < m && sosedi.find({els[x][y+1], x, y+1}) == sosedi.end()) {
                sosedi.insert({els[x][y+1], x, y+1}); 
                cnt += els[x][y+1];
            }

        }

        if (sosedi.size() < 3*smth.size()) {cout << "No" << endl; return;}

        if (sosedi.size() == 3*smth.size()) ans += cnt;

        if (sosedi.size() == 3*smth.size() + 1) ans += cnt - (*sosedi.begin())[0];
    }
    cout << ans << endl;
    // cout << "YYAY" << endl;

}

signed    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	int t = 1; 
    // cin >> t;
    while (t--)solve();
}


Compilation message (stderr)

covering.cpp:101:18: error: 'int freopen' redeclared as different kind of entity
  101 | signed    freopen("input.txt", "r", stdin);
      |                  ^
In file included from /usr/include/c++/11/cstdio:42,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:46,
                 from covering.cpp:1:
/usr/include/stdio.h:265:14: note: previous declaration 'FILE* freopen(const char*, const char*, FILE*)'
  265 | extern FILE *freopen (const char *__restrict __filename,
      |              ^~~~~~~
covering.cpp:102:12: error: expected constructor, destructor, or type conversion before '(' token
  102 |     freopen("output.txt", "w", stdout);
      |            ^
covering.cpp:105:5: error: expected unqualified-id before 'while'
  105 |     while (t--)solve();
      |     ^~~~~
covering.cpp:106:1: error: expected declaration before '}' token
  106 | }
      | ^