답안 #223517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223517 2020-04-15T10:25:55 Z maomao90 Checker (COCI19_checker) C++14
29 / 110
3000 ms 4816 KB
#include <cstdio>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <tuple>
#include <cmath>
#include <cassert>

using namespace std;

typedef pair <int, int> ii;
typedef pair <ii, int> iii;

struct pair_hash
{
	template <class T1, class T2>
	std::size_t operator() (const std::pair<T1, T2> &pair) const
	{
		return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
	}
};

int tc;
int N;
char temps[200005];
iii diagonals[200005];
unordered_map <ii, int, pair_hash> colours;
bool isInvalid[200005];
int impt1[200005], impt2[200005];

bool comp(iii right, iii left)
{
    int rx, ry, lx, ly;
    tie(rx, ry) = right.first; tie(lx, ly) = left.first;
    if (abs(rx - ry) < abs(lx - ly)) return true;
    else if (abs(rx - ry) == abs(lx - ly))
    {
        if (rx < ry) return true;
    }
    return false;
}

int main()
{
    scanf("%d%d", &tc, &N);
    //assert(1 == 2);
    scanf(" %s", temps);
    for (int i = 1; i <= N; i++)
    {
        char temp = temps[i - 1];
        if (i == N)
        {
            colours[ii(i, 1)] = (int) temp - '0';
            colours[ii(1, i)] = (int) temp - '0';
        }
        else
        {
            colours[ii(i, i + 1)] = (int) temp - '0';
            colours[ii(i + 1, i)] = (int) temp - '0';
        }
        if (i == N) impt1[i] = 1;
        else impt1[i] = i + 1;
        if (i == 1) impt2[i] = N;
        else impt2[i] = i - 1;
    }
    for (int i = 0; i < N - 3; i++)
    {
        int X, Y, C; scanf("%d%d%d", &X, &Y, &C);
        if (X > Y) swap(X, Y);
        diagonals[i] = iii(ii(X, Y), C);
        colours[ii(X, Y)] = C;
        colours[ii(Y, X)] = C;
    }
    sort(diagonals, diagonals + N - 3, comp);
    for (int i = 0; i < N - 3; i++)
    {
        int x, y, c;
        tie(x, y) = diagonals[i].first; c = diagonals[i].second;
        if (isInvalid[x] || isInvalid[y])
        {
            printf("neispravna triangulacija\n");
            return 0;
        }
        int impt;
        if (impt1[x] == impt1[y] || impt1[x] == impt2[y]) impt = impt1[x];
        else impt = impt2[x];
        isInvalid[impt] = true;
        if (impt1[x] == impt) impt1[x] = y;
        else impt2[x] = y;
        if (impt1[y] == impt) impt1[y] = x;
        else impt2[y] = x;
    }
    for (int i = 1; i <= N; i++)
    {
        impt1[i] = i == N ? 1 : i + 1;
        impt2[i] = i == 1 ? N : i - 1;
    }
    for (int i = 0; i < N - 3; i++)
    {
        int x, y, c;
        tie(x, y) = diagonals[i].first; c = diagonals[i].second;
        int impt;
        if (impt1[x] == impt1[y] || impt1[x] == impt2[y]) impt = impt1[x];
        else impt = impt2[x];

        if (colours[ii(x, y)] == colours[ii(x, impt)] ||
            colours[ii(x, y)] == colours[ii(y, impt)] ||
            colours[ii(x, impt)] == colours[ii(y, impt)])
        {
            printf("neispravno bojenje\n");
            return 0;
        }
        if (impt1[x] == impt) impt1[x] = y;
        else impt2[x] = y;
        if (impt1[y] == impt) impt1[y] = x;
        else impt2[y] = x;
    }
    printf("tocno\n");
    return 0;
}

Compilation message

checker.cpp: In function 'int main()':
checker.cpp:77:19: warning: variable 'c' set but not used [-Wunused-but-set-variable]
         int x, y, c;
                   ^
checker.cpp:100:19: warning: variable 'c' set but not used [-Wunused-but-set-variable]
         int x, y, c;
                   ^
checker.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &tc, &N);
     ~~~~~^~~~~~~~~~~~~~~~~
checker.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %s", temps);
     ~~~~~^~~~~~~~~~~~~~
checker.cpp:68:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int X, Y, C; scanf("%d%d%d", &X, &Y, &C);
                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 45 ms 896 KB Output is correct
9 Correct 46 ms 896 KB Output is correct
10 Correct 26 ms 896 KB Output is correct
11 Correct 25 ms 896 KB Output is correct
12 Correct 26 ms 896 KB Output is correct
13 Correct 35 ms 888 KB Output is correct
14 Correct 26 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3067 ms 4800 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3078 ms 4816 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 45 ms 896 KB Output is correct
9 Correct 46 ms 896 KB Output is correct
10 Correct 26 ms 896 KB Output is correct
11 Correct 25 ms 896 KB Output is correct
12 Correct 26 ms 896 KB Output is correct
13 Correct 35 ms 888 KB Output is correct
14 Correct 26 ms 896 KB Output is correct
15 Execution timed out 3067 ms 4800 KB Time limit exceeded
16 Halted 0 ms 0 KB -