답안 #301224

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
301224 2020-09-17T18:11:02 Z joseacaz 식물 비교 (IOI20_plants) C++17
0 / 100
4000 ms 16484 KB
#include "plants.h"
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long ll;
typedef vector<int> vi;

const int MAXN = 2e5 + 5;
int N, k, vis[MAXN];
vi r, Graph[MAXN];

void sub(int idx)
{
    for(int i = 1; i < k; i++)
    {
        int id = ((idx - i)%N + N)%N;
        if(r[id] > 0)
        {
            r[id]--;
            if(r[id] == 0)
                Graph[idx].pb(id);
        }
    }
}

int getnext(int idx)
{
    for(int i = 1; i < N; i++)
    {
        int id = ((idx + i)%N + N)%N;
        if(i < k && !vis[id])
            Graph[idx].pb(id);
        if(r[id] == 0 && !vis[id])
            return id;
    }
    return idx;
}

void init(int _k, vi _r)
{
    k = _k;
    swap(r, _r);
    N = r.size();
    
    int maxIdx = 0;
    for(int i = 0; i < N; i++)
    {
        if(r[i] != 0)
            continue;
        int maxim = 1;
        for(int j = 1; j < k; j++)
        {
            int id = ((i - j)%N + N)%N;
            if(r[id] == 0)
                maxim = 0;
        }
        if(maxim)
            maxIdx = i;
    }
    
    while(!vis[maxIdx])
    {
        vis[maxIdx] = 1;
        sub(maxIdx);
        maxIdx = getnext(maxIdx);
    }
	return;
}

int dfs(int a, int b)
{
    if(a == b)
        return 1;
    for(auto i : Graph[a])
        if(dfs(i, b))
            return 1;
    return 0;
}

int compare_plants(int x, int y)
{
    int aux = dfs(x, y), aux2 = dfs(y, x);
    if(!aux && !aux2)
        return 0;
    else if(aux)
        return 1;
    else
        return -1;
	return 0;
}

Compilation message

plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:89:5: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   89 |     else
      |     ^~~~
plants.cpp:91:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   91 |  return 0;
      |  ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 76 ms 7800 KB Output is correct
7 Correct 525 ms 8788 KB Output is correct
8 Correct 540 ms 16248 KB Output is correct
9 Correct 2574 ms 16484 KB Output is correct
10 Execution timed out 4094 ms 15352 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Execution timed out 4062 ms 4992 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Execution timed out 4062 ms 4992 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Execution timed out 4070 ms 7672 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 5 ms 4992 KB Output is correct
6 Incorrect 7 ms 5120 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 5024 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Execution timed out 4094 ms 5248 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 76 ms 7800 KB Output is correct
7 Correct 525 ms 8788 KB Output is correct
8 Correct 540 ms 16248 KB Output is correct
9 Correct 2574 ms 16484 KB Output is correct
10 Execution timed out 4094 ms 15352 KB Time limit exceeded
11 Halted 0 ms 0 KB -