Submission #303189

# Submission time Handle Problem Language Result Execution time Memory
303189 2020-09-20T00:44:03 Z qiangbao Comparing Plants (IOI20_plants) C++14
0 / 100
4000 ms 384 KB
#include <iostream>
#include <vector>
#include <set>
#include "plants.h"

#define INF 1000000007

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;
    n=r.size();
    
    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)
                continue;
            f-=n;
            ans[f]=i;
            zero.erase(f), zero.erase(f+n);
            for(i=1;i<k;i++){
                r[f+i]--;
                if(r[f+i]==0)
                    zero.insert(f+i);
            }
            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});
//    cout << compare_plants(1, 2) << endl;
//    cout << compare_plants(1, 3) << endl;
//    cout << compare_plants(1, 4) << endl;
//    cout << compare_plants(2, 3) << endl;
//    cout << compare_plants(2, 4) << endl;
//    cout << compare_plants(3, 4) << endl;
//
//    return 0;
//}
# Verdict Execution time Memory Grader output
1 Execution timed out 4062 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4070 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4070 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4058 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4075 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4077 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4062 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -