# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
154017 | hocky | NLO (COCI18_nlo) | C++14 | 831 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#define pb push_back
using namespace std;
typedef long long LL;
inline void fasterios(){
//Do not use if interactive
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
LL n,m,k;
struct dt{
LL x,y,r;
};
vector <dt> all;
struct dtl{
bool isOn;
LL pos, idx;
bool operator<(const dtl &other)const{
if(pos != other.pos) return pos < other.pos;
return isOn > other.isOn;
}
};
int main(){
fasterios();
cin >> m >> n >> k;
for(int i = 1;i <= k;i++){
dt tmp; cin >> tmp.y >> tmp.x >> tmp.r;
all.pb(tmp);
}
reverse(all.begin(),all.end());
LL ans = 0;
for(int i = 1;i <= n;i++){
vector <dtl> lines;
lines.pb({1,1,k});
lines.pb({0,m,k});
for(int j = 0;j < all.size();j++){
LL dist_x = (all[j].x-i);
LL diff = (all[j].r*all[j].r) - (dist_x*dist_x);
if(diff < 0) continue;
diff = sqrt(diff);
lines.pb({1,all[j].y-diff,j});
lines.pb({0,all[j].y+diff,j});
}
sort(lines.begin(),lines.end());
set <LL> active_lines;
LL pre = 0;
for(int j = 0;j < lines.size();j++){
if(lines[j].isOn == 1){
if(pre < lines[j].pos-1){
LL smallest = *(active_lines.begin());
ans += (lines[j].pos-1-pre)*smallest;
pre = lines[j].pos-1;
}
active_lines.insert(lines[j].idx);
}else{
if(pre < lines[j].pos){
LL smallest = *(active_lines.begin());
ans += (lines[j].pos-pre)*smallest;
pre = lines[j].pos;
}
active_lines.erase(lines[j].idx);
}
}
}
printf("%lld",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |