답안 #97458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97458 2019-02-16T10:40:58 Z KLPP NLO (COCI18_nlo) C++14
33 / 110
65 ms 66560 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long int lld;
typedef pair<int,int> pii;
class intervals{
	vector<pair<int,pii > >v;
	public:
	void insert(int val, int x, int y){
		v.push_back(pair<int,pii>(x,pii(val,0)));
		v.push_back(pair<int,pii>(y+1,pii(val,1)));  
	}
	lld calculate(){
		sort(v.begin(),v.end());
		set<int> s;
		set<int>::iterator it;
		lld point=0;
		lld ans=0;
		for(int i=0;i<v.size();i++){
			if(s.size()>0){
				it=s.end();
				it--;
				lld s=*it;
				ans+=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 ans;
	}
	void print(){
		for(int i=0;i<v.size();i++){
			cout<<v[i].first<<" "<<v[i].second.first<<" "<<v[i].second.second<<endl;
		}
	}
};
lld absol(lld a){
	if(a>0)return a;
	return -a;
}
lld f(lld a, lld b){
	if(a<b)return -1;
	lld lo=0;
	lld 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;
	intervals *SETS[m];
	for(int i=0;i<m;i++){
		SETS[i]=new intervals();
	}
	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]->insert(i,x-diff2,x+diff2);
			}
		}
	}lld ans=0;
	for(int i=0;i<m;i++){
		ans+=k*n-SETS[i]->calculate();
		//SETS[i]->print();
	}cout<<ans<<endl;
	return 0;
}

Compilation message

nlo.cpp: In member function 'lld intervals::calculate()':
nlo.cpp:19:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<v.size();i++){
               ~^~~~~~~~~
nlo.cpp: In member function 'void intervals::print()':
nlo.cpp:35:16: 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:58:6: warning: variable 'arr' set but not used [-Wunused-but-set-variable]
  int arr[n][m];
      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 4224 KB Output is correct
2 Correct 31 ms 6016 KB Output is correct
3 Correct 65 ms 63992 KB Output is correct
4 Runtime error 61 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 59 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 2 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 2 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 1 ms 256 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)