답안 #1079505

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079505 2024-08-28T15:57:00 Z bleahbleah 식물 비교 (IOI20_plants) C++17
0 / 100
2 ms 348 KB
#include "plants.h"
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
#define sz(x) ((int)(x).size())

int K, N;
const int nmax = 2e5 + 5;

namespace Queue {
   int next[nmax];
   int inside[nmax];
   
   set<int> heads;
   void insert(int node) {
      cerr << "inserez " << node << '\n';
      heads.emplace(node);
      inside[node] = 1;
      next[node] = -1;
      for(int i = (node + 1) % N, d = 1; i != node && d < K; d++, i = (i + 1) % N) {
         if(inside[i]) {
            if(heads.count(i))
               heads.erase(i);
            next[node] = i;
         }
      }
      for(int i = (node - 1 + N) % N, d = 1; i != node && d < K; d++, i = (i - 1 + N) % N) {
         if(inside[i]) {
            heads.erase(node);
            next[i] = node;
         }
      }
   }
   
   vector<int> prune() {
      vector<int> rez;
      for(auto x : heads)
         rez.emplace_back(x), inside[x] = 0;
      heads.clear();
      for(auto x : rez)
         if(next[x] != -1) heads.emplace(next[x]);
      return rez;
   }
}

vector<int> topsort;

void init(int k__, std::vector<int> r) {
   K = k__;
   N = sz(r);
   topsort.resize(N);
   
   vector<int> erased(N, 0);
   for(int i = 0; i < sz(r); i++) 
      if(r[i] == 0) erased[i] = 1, Queue::insert(i);
   
   int color = 0;
   while(sz(Queue::heads)) {
      auto rem = Queue::prune();
      //for(auto x : rem) cerr << x << ' ';
      //cerr << '\n';
      ++color;
      for(auto x : rem) topsort[x] = color;
      
      for(auto x : rem) {
         for(int i = (x - 1 + N) % N, d = 1; d < K; d++, i = (i - 1 + N) % N) {
            if(erased[i]) continue;
            r[i]--;
            if(r[i] == 0) erased[i] = 1, Queue::insert(i);
         }
      }
   }
   
	return;
}

int compare_plants(int x, int y) {
	return topsort[x] < topsort[y]? 1 : topsort[x] == topsort[y]? 0 : -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 2 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 2 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -