Submission #658818

# Submission time Handle Problem Language Result Execution time Memory
658818 2022-11-15T02:45:32 Z aebov T-Covering (eJOI19_covering) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define pb push_back
#define F first
#define S second
#define pii pair<int ,int>

using namespace std;

const int N = (int)1e6 + 6;
int n, m, k, g[N], okt = 0;
vector<int> vc, adj[N];
int hx[] = {-1, 1, 0, 0};
int hy[] = {0, 0, 1, -1};
bool vis[N], ok[N];

bool valid(int i,int j){return (i >= 0 && i < n && j >= 0 && j < m);}
void dfs(int v){
	vis[v] = 1;
	if(!ok[v])vc.pb(g[v]);
	else okt ++;
	for(auto u : adj[v])
	{
		if(vis[u])continue;
		dfs(u);
	}
}
int32_t main(){
//	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for(int i = 0; i < n; i ++)
		for(int j = 0; j < m;j ++){
			int v = i*m +j;
			cin >> g[v];
            ok[v] = vis[v] = 0;
		}
	cin >> k;
	int ans = 0;
	for(int i = 0; i < k; i ++){
		int r, c;cin >> r >> c;
		int v = r*m+c;
	//	cout << "V : " << v << endl;
		ok[v] = 1, ans += g[v];
		vector<pii> d = {{-1,0}, {1,0}, {0,1}, {0,-1}};
        for(auto it:d) {
            int di = it.x, dj = it.y;
            int ni = r + di, nj = c + dj;
            int u = ni*m+nj;
            if (!in_limits(ni, nj)) continue;
            adj[v].pb(u);
            adj[u].pb(v);
        }
	}
	for(int r = 0; r < n; r ++){
		for(int c = 0; c < m; c ++){
			int v = r*m + c;
			if(!vis[v] && ok[v]){
				okt = 0;
				vc.clear();
				dfs(v);
				if(vc.size() < 3 * okt)return cout << "NO\n", 0;
				sort(vc.begin(), vc.end());
	//			cout << i << " " << j << " : " ;
    //          for(auto x : vc)cout << x << " ";
   //           cout << endl;
				for(int f = 1; f <= 3*okt; f ++)ans += vc[vc.size() - f];
			}
		}
	}
    cout << ans << "\n";
    return 0;
}

Compilation message

covering.cpp: In function 'int32_t main()':
covering.cpp:47:25: error: 'struct std::pair<long int, long int>' has no member named 'x'
   47 |             int di = it.x, dj = it.y;
      |                         ^
covering.cpp:48:39: error: 'dj' was not declared in this scope; did you mean 'nj'?
   48 |             int ni = r + di, nj = c + dj;
      |                                       ^~
      |                                       nj
covering.cpp:50:18: error: 'in_limits' was not declared in this scope
   50 |             if (!in_limits(ni, nj)) continue;
      |                  ^~~~~~~~~
covering.cpp:62:18: warning: comparison of integer expressions of different signedness: 'std::vector<long int>::size_type' {aka 'long unsigned int'} and 'int64_t' {aka 'long int'} [-Wsign-compare]
   62 |     if(vc.size() < 3 * okt)return cout << "NO\n", 0;
      |        ~~~~~~~~~~^~~~~~~~~