#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
nlo.cpp: In function 'void Upd()':
nlo.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<otr.size(); i++)
~^~~~~~~~~~~
nlo.cpp:25:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0; j<otr[i].size(); j++) otr[i][j].cost++;
~^~~~~~~~~~~~~~
nlo.cpp: In function 'void Add(int, int, int)':
nlo.cpp:31:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<otr[x].size(); i++)
~^~~~~~~~~~~~~~
nlo.cpp:36:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=i; j<otr[x].size(); j++)
~^~~~~~~~~~~~~~
nlo.cpp:40:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int c=j+1; c<otr[x].size(); c++) add.pb(otr[x][c]);
~^~~~~~~~~~~~~~
nlo.cpp: In function 'int main()':
nlo.cpp:77:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
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;
~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1792 KB |
Output is correct |
2 |
Correct |
28 ms |
5120 KB |
Output is correct |
3 |
Correct |
25 ms |
5632 KB |
Output is correct |
4 |
Correct |
132 ms |
28536 KB |
Output is correct |
5 |
Correct |
176 ms |
30200 KB |
Output is correct |
6 |
Runtime error |
286 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Runtime error |
329 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Runtime error |
226 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
261 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Runtime error |
214 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |