# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
97464 |
2019-02-16T10:53:25 Z |
KLPP |
NLO (COCI18_nlo) |
C++14 |
|
1358 ms |
492 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;
vector<pair<int,pii > > v;
lld calculate(){
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 k;
cin>>k;
int circles[k][3];
for(int i=1;i<=k;i++){
int x,y,r;
cin>>x>>y>>r;
x--;y--;
circles[i-1][0]=x;
circles[i-1][1]=y;
circles[i-1][2]=r;
//cout<<x<<" "<<y<<endl;
}
lld ans=0;
lld diff,diff2;
int x,y;
for(int i=0;i<m;i++){
for(int val=1;val<=k;val++){
x=circles[val-1][0];
y=circles[val-1][1];
diff=absol(i-y);
lld diff2=f(circles[val-1][2],diff);
if(diff2!=-1){
//cout<<r<<" "<<diff<<" "<<f(r,diff)<<endl;
//cout<<j<<" "<<x-diff2<<" "<<x+diff2<<endl;
v.push_back(pair<int,pii>(x-diff2,pii(val,0)));
v.push_back(pair<int,pii>(x+1+diff2,pii(val,1)));
}
}
ans+=k*n-calculate();
v.clear();
//SETS[i]->print();
}cout<<ans<<endl;
return 0;
}
Compilation message
nlo.cpp: In function 'lld calculate()':
nlo.cpp:16: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:66:11: warning: unused variable 'diff2' [-Wunused-variable]
lld diff,diff2;
^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
256 KB |
Output is correct |
2 |
Correct |
21 ms |
384 KB |
Output is correct |
3 |
Correct |
16 ms |
384 KB |
Output is correct |
4 |
Correct |
77 ms |
396 KB |
Output is correct |
5 |
Correct |
80 ms |
356 KB |
Output is correct |
6 |
Correct |
518 ms |
360 KB |
Output is correct |
7 |
Correct |
218 ms |
260 KB |
Output is correct |
8 |
Correct |
1026 ms |
492 KB |
Output is correct |
9 |
Correct |
343 ms |
384 KB |
Output is correct |
10 |
Correct |
1358 ms |
376 KB |
Output is correct |