# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
252829 | 2020-07-26T10:26:53 Z | user202729 | Circle selection (APIO18_circle_selection) | C++17 | 3000 ms | 49612 KB |
// ... // already failed twice. #ifndef LOCAL #define NDEBUG 1 #endif #include<bits/stdc++.h> int main(){ std::ios::sync_with_stdio(0);std::cin.tie(0); using Index=int; // for circles struct Circle{ int x, y, r; bool intersect(Circle other) const{ assert(r>0); assert(other.r>0); return int64_t(x-other.x)*(x-other.x)+int64_t(y-other.y)*(y-other.y)<= int64_t(r+other.r)*(r+other.r); } }; int number; std::cin>>number; std::vector<Circle> circles(number); for(auto& [x, y, r]: circles) std::cin>>x>>y>>r; // r==0: deleted struct A{ Index index; int r; bool operator<(A other) const{ return r!=other.r ? r<other.r: index>other.index; } }; std::priority_queue<A> q; for(Index index=0; index<number; ++index) q.push({index, circles[index].r}); auto const callIf=[&](auto object, int key, auto function){ auto const iterator=object.find(key); if(iterator!=object.end()) function(iterator->second); }; std::vector<int> result(number); assert((result.assign(number, -1), true)); std::map<int, std::map<int, std::vector<Index>>> grid; for(int step=30; step;--step){ grid.clear(); for(Index index=0; index<number; ++index){ auto const [x, y, r]=circles[index]; if(r==0) continue; assert(r<(1<<step)); grid[x>>step][y>>step].push_back(index); } while(true){ if(q.empty()) goto break_outer; auto [index, r_]=q.top(); auto const cur=circles[index]; auto const [x, y, r]=cur; if(r==0) { q.pop(); continue; } assert(r==r_); if(r<((1<<step)>>1)) break; // goto next step -- without popping from q q.pop(); circles[index].r=0; assert(result[index]==-1); result[index]=index; for(int a=-2; a<=2;++a) for(int b=-2; b<=2; ++b){ callIf(grid, (x>>step)+a, [&](auto& it){ callIf(it, (y>>step)+b, [&](auto& it){ #if not NDEBUG std::set<Index> called; #endif //std::erase_if(it,[&](Index index1){ // "since C++20". Nice anyway. it.erase(std::remove_if(begin(it), end(it), [&](Index index1){ assert(called.insert(index1).second); if(a==0 and b==0){ if(index1==index) return true; }else assert(index1!=index); auto& cur1=circles[index1]; assert(cur1.r>0); if(cur1.intersect(cur)){ assert(result[index1]==-1); result[index1]=index; cur1.r=0; return true; } else return false; }),it.end()); }); }); } } } break_outer: for(Index index=0; index<number; ++index){ auto const [x, y, r]=circles[index]; assert(result[index]!=-1); assert(r==0); } for(auto it: result) std::cout<<it+1<<' '; std::cout<<'\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Incorrect | 0 ms | 384 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 208 ms | 19492 KB | Output is correct |
2 | Incorrect | 216 ms | 19688 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Execution timed out | 3077 ms | 28172 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3070 ms | 49612 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Incorrect | 0 ms | 384 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Incorrect | 0 ms | 384 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |