Submission #97460

# Submission time Handle Problem Language Result Execution time Memory
97460 2019-02-16T10:45:24 Z KLPP NLO (COCI18_nlo) C++14
33 / 110
71 ms 66560 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long int lld;
typedef pair<int,int> pii;
set<int> s;
set<int>::iterator it;
lld A;
lld point;
lld calculate(vector<pair<int,pii > >v){
	sort(v.begin(),v.end());
	s.clear();
	point=0;
	A=0;
	for(int i=0;i<v.size();i++){
		if(s.size()>0){
			it=s.end();
			it--;
			lld s=*it;
			A+=s*(v[i].first-point);
			//cout<<s<<" "<<v[i].first-point<<endl;
		}
		point=v[i].first;
		//cout<<ans<<endl;
		if(v[i].second.second){
			s.erase(v[i].second.first);
		}else s.insert(v[i].second.first);
	}return A;
}
lld absol(lld a){
	if(a>0)return a;
	return -a;
}
lld lo,hi;
lld f(lld a, lld b){
	if(a<b)return -1;
	lo=0;
	hi=1000000000;
	while(hi-lo>1){
		lld mid=(hi+lo)/2;
		if(mid*mid+b*b<=a*a){
			lo=mid;
		}else hi=mid;
	}return lo;
}
int main(){
	int n,m;
	cin>>n>>m;
	int arr[n][m];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)arr[i][j]=0;
	}int k;
	cin>>k;
	vector<pair<int,pii > > SETS[m];
	for(int i=1;i<=k;i++){
		int x,y,r;
		cin>>x>>y>>r;
		x--;y--;
		//cout<<x<<" "<<y<<endl;
		for(int j=0;j<m;j++){
			lld diff=absol(j-y);
			lld diff2=f(r,diff);
			if(diff2!=-1){
				//cout<<r<<" "<<diff<<" "<<f(r,diff)<<endl;
				//cout<<j<<" "<<x-diff2<<" "<<x+diff2<<endl;
				SETS[j].push_back(pair<int,pii>(x-diff2,pii(i,0)));
				SETS[j].push_back(pair<int,pii>(x+1+diff2,pii(i,1)));
			}
		}
	}
	
	lld ans=0;
	for(int i=0;i<m;i++){
		ans+=k*n-calculate(SETS[i]);
		//SETS[i]->print();
	}cout<<ans<<endl;
	return 0;
}

Compilation message

nlo.cpp: In function 'lld calculate(std::vector<std::pair<int, std::pair<int, int> > >)':
nlo.cpp:15:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v.size();i++){
              ~^~~~~~~~~
nlo.cpp: In function 'int main()':
nlo.cpp:49:6: warning: variable 'arr' set but not used [-Wunused-but-set-variable]
  int arr[n][m];
      ^~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4224 KB Output is correct
2 Correct 32 ms 6016 KB Output is correct
3 Correct 64 ms 63864 KB Output is correct
4 Runtime error 62 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 71 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 2 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)