#include <bits/stdc++.h>
#ifndef BALBIT
#include "plants.h"
#endif // BALBIT
using namespace std;
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x.size())
#define pb push_back
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y){cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define bug(...)
#define endl '\n'
#endif // BALBIT
#define REP(i,n) for (int i = 0; i<n;++i)
#define REP1(i,n) for (int i = 1; i<=n;++i)
const int maxn = 5005;
int group[maxn];
int R[maxn];
bool added[maxn];
int n;
inline int F(int x) {
return x >=n ? x-n: (x<0?x+n:x);
}
void init(int k, vector<int> r) {
n = SZ(r);
REP(i,n) R[i] = r[i];
// REP(i,n) {
// if (r[i] == 0)
// for (int j = 1; j<k; ++j) {
// R[F(i+j)] ++;
// }
// }
memset(group, -1, sizeof group);
for (int gg = 0; gg < n; ++gg) {
vector<int> tmp2;
vector<int> tmp;
REP(i,n) {
if (R[i] == 0 && !added[i]) {
added[i] = 1; tmp.pb(i);
}
}
for (int x : tmp)
for (int j = 1; j<k; ++j) {
R[F(x+j)] ++;
}
REP(i,n) {
if(group[i] == -1 && R[i] == 0) {
group[i] = gg; tmp2.pb(i);
}
}
for (int x : tmp2) {
for (int j = 1; j<k; ++j) {
R[F(x+j)]--;
}
for (int j = 1; j<k; ++j) {
R[F(x-j)]--;
}
}
// REP(i,n) cout<<R[i]<<' ';
// cout<<endl;
}
//#ifdef BALBIT
REP(i,n) {
bug(i,group[i]);
assert(group[i] != -1);
}
//#endif
// REP(i,n) bug(i,group[i]);
}
int compare_plants(int x, int y) {
if (group[x] == group[y]) return 0;
return group[x] > group[y] ? -1:1;
}
#ifdef BALBIT
signed main(){
bug(1,2);
init(3, {0, 1, 1, 2});
bug(compare_plants(0,2));
bug(compare_plants(1,2));
bug(compare_plants(0,3));
bug(compare_plants(1,3));
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
12 ms |
492 KB |
Output is correct |
7 |
Correct |
304 ms |
5356 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
12 ms |
492 KB |
Output is correct |
10 |
Correct |
300 ms |
5228 KB |
Output is correct |
11 |
Correct |
255 ms |
5228 KB |
Output is correct |
12 |
Correct |
258 ms |
5228 KB |
Output is correct |
13 |
Correct |
320 ms |
5232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
12 ms |
492 KB |
Output is correct |
7 |
Correct |
304 ms |
5356 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
12 ms |
492 KB |
Output is correct |
10 |
Correct |
300 ms |
5228 KB |
Output is correct |
11 |
Correct |
255 ms |
5228 KB |
Output is correct |
12 |
Correct |
258 ms |
5228 KB |
Output is correct |
13 |
Correct |
320 ms |
5232 KB |
Output is correct |
14 |
Runtime error |
52 ms |
7916 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
380 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |