Submission #958319

# Submission time Handle Problem Language Result Execution time Memory
958319 2024-04-05T11:53:05 Z moonrabbit2 None (JOI12_invitation) C++17
30 / 100
128 ms 131072 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=array<int,2>;
using tii=array<int,3>;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
const int N=2005;
int n,m,s,k,p[N];
vector<tii> E;
ll ans;
int Find(int x){
	if(!p[x]) return x;
	return p[x]=Find(p[x]);
}
bool Union(int x,int y){
	x=Find(x); y=Find(y);
	if(x==y) return false;
	p[y]=x; return true;
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>m>>s>>k;
	for(int l,r,s,e,c,i=1;i<=k;i++){
		cin>>l>>r>>s>>e>>c;
		for(int j=l;j<r;j++) E.push_back({c,j,j+1});
		for(int j=s;j<e;j++) E.push_back({c,n+j,n+j+1});
		E.push_back({c,l,n+s});
	}
	sort(E.begin(),E.end(),greater<>());
	for(auto [c,u,v]: E) if(Union(u,v)) ans+=c;
	for(int i=2;i<=n+m;i++) if(Find(1)!=Find(i)){
		cout<<"-1\n";
		return 0;
	}
	cout<<ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 1208 KB Output is correct
3 Correct 7 ms 2004 KB Output is correct
4 Correct 2 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3536 KB Output is correct
2 Correct 38 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 26304 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 128 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 89 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 56 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 58 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 56 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 59 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 55 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -