# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
230514 | topovik | NLO (COCI18_nlo) | C++14 | 329 ms | 65540 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 <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define INF 1000000000
#define N (int)1e6+2
using namespace std;
typedef long long ll;
typedef long double ld;
struct X{
int l;
int r;
int cost;
X (int l, int r) : l(l),r(r),cost(0){};
};
vector <vector <X> > otr;
void Upd()
{
for (int i=0; i<otr.size(); i++)
for (int j=0; j<otr[i].size(); j++) otr[i][j].cost++;
}
void Add(int x, int l, int r)
{
vector <X> add;
for (int i=0; i<otr[x].size(); i++)
if (otr[x][i].r>=l)
{
if (otr[x][i].l<l) add.pb(*(new X(otr[x][i].l,l-1))),add.back().cost=otr[x][i].cost;
add.pb(*(new X(l,r)));
for (int j=i; j<otr[x].size(); j++)
if (otr[x][j].r>=r)
{
if (otr[x][j].r>r) add.pb(*(new X(r+1,otr[x][j].r))),add.back().cost=otr[x][j].cost;
for (int c=j+1; c<otr[x].size(); c++) add.pb(otr[x][c]);
break;
}
break;
}
else add.pb(otr[x][i]);
otr[x]=add;
}
int main()
{
ios_base::sync_with_stdio(0);
iostream::sync_with_stdio(0);
cin.tie(0);
int n,m,k;
cin>>n>>m>>k;
otr.resize(n);
for (int i=0; i<n; i++) otr[i].pb(*(new X(0,m-1)));
for (int i=0; i<k; i++)
{
Upd();
int x,y,r;
cin>>x>>y>>r;
x--,y--;
for (int j=0; j<=r; j++)
{
int kol=(int)(ld)sqrt(r*r-((r-j)*(r-j)));
Add(x-r+j,y-kol,y+kol),Add(x+r-j,y-kol,y+kol);
}
}
ll ans=0;
/*for (int i=0; i<n; i++)
{
for (int j=0; j<otr[i].size(); j++) cout<<"("<<otr[i][j].l<<" "<<otr[i][j].r<<") - "<<otr[i][j].cost<<endl;
cout<<endl;
}*/
for (int i=0; i<n; i++)
for (int j=0; j<otr[i].size(); j++) ans+=(ll)(otr[i][j].r-otr[i][j].l+1)*(ll)otr[i][j].cost;
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |