답안 #303221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
303221 2020-09-20T02:17:17 Z qiangbao 식물 비교 (IOI20_plants) C++14
0 / 100
152 ms 3324 KB
#include <iostream>
#include <vector>
#include <set>
#include "plants.h"

using namespace std;

int n;

set<int> zero;
set<int> cur;
set<int>:: iterator it, it2;

int ans[200001];

void init(int k, vector<int> r)
{
    int i, j;
    n=r.size();
    
    for(i=0;i<n;i++)
        r[i]=k-1-r[i];
    for(i=0;i<n;i++)
        if(r[i]==0)
            zero.insert(i);
    for(i=1;i<=n;i++){
        cur.clear();
        it=zero.begin();
        while(it!=zero.end()){
            cur.insert(*it), cur.insert(*it+n);
            it++;
        }
        it=cur.begin();
        while(it!=cur.end()){
            it2=it, it2++;
            if(it2==cur.end())
                break;
            if(*it2-*it<k){
                cur.erase(*it2);
                cur.erase(*it2+n);
            }
            it++;
        }
        it=cur.begin();
        while(it!=cur.end()){
            int f=*it;
            if(f<n){
                it++;
                continue;
            }
            f-=n;
            ans[f]=i;
            zero.erase(f), zero.erase(f+n);
            for(j=0;j<k;j++){
                int f2=(f-j);
                if(f2<0)
                    f2+=n;
                r[f2]--;
                if(r[f2]==0)
                    zero.insert(f2);
            }
            it++;
        }
    }
}

int compare_plants(int x, int y)
{
    if(ans[x]==ans[y])
        return 0;
    else if(ans[x]>ans[y])
        return 1;
    return -1;
}

//int main()
//{
//    init(2, {1, 0, 1, 0, 1, 0});
//    cout << compare_plants(0, 1) << endl;
//    cout << compare_plants(0, 2) << endl;
//    cout << compare_plants(0, 3) << endl;
//    cout << compare_plants(1, 2) << endl;
//    cout << compare_plants(1, 3) << endl;
//    cout << compare_plants(2, 3) << endl;
//    cout << compare_plants(1, 4) << endl;
//    init(2, {0, 1, 0, 1});
//    cout << compare_plants(0, 3) << endl;
//    cout << compare_plants(1, 3) << endl;
//
//    return 0;
//}

// 5, 4, 6, 1, 3, 2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Incorrect 0 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 152 ms 3308 KB Output is correct
8 Incorrect 2 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 152 ms 3308 KB Output is correct
8 Incorrect 2 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 72 ms 3324 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 1 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Incorrect 0 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Incorrect 0 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -