답안 #1004746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1004746 2024-06-21T13:35:18 Z atom Logičari (COCI21_logicari) C++17
10 / 110
164 ms 604 KB
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
 
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
 
const int N = 352;
// 1: last position of x, -1: second-last position of x -> sum(l, r) = 0-> non-unique subarray, > 0: unique

vector <int> adj[N];
int n;

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int x, y; cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    bool sub1 = true;
    for (int i = 1; i <= n; ++i) {
        if ((int) adj[i].size() != 2) sub1 = false;
    }

    if (sub1) {
        cout << (n % 4 == 0? (n / 2) : -1) << "\n";
        return 0;
    }

    bool sub2 = (n <= 20);
    if (sub2) {
        int res = 1e9;
        for (int msk = 0; msk < (1 << n); ++msk) {
            vector <bool> b(n + 1, 0);
            int cur = 0;
            for (int i = 1; i <= n; ++i) { 
                if (msk & (1 << (i - 1))) {
                    b[i] = 1;
                    ++cur;
                }
            }

            bool ans = true;
            for (int i = 1; i <= n; ++i) {
                int cnt = 0;
                for (int j : adj[i])
                    if (b[j])
                        ++cnt;
                if (cnt != 1) ans = false;
            }

            if (ans) {
                res = min(res, cur);
            }
        }
        cout << (res != 1e9? res : -1) << "\n";
        return 0;
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Runtime error 0 ms 600 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 452 KB Output is correct
2 Correct 134 ms 348 KB Output is correct
3 Correct 137 ms 348 KB Output is correct
4 Correct 131 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 67 ms 600 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 32 ms 460 KB Output is correct
9 Correct 130 ms 444 KB Output is correct
10 Correct 164 ms 348 KB Output is correct
11 Correct 21 ms 348 KB Output is correct
12 Correct 131 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 452 KB Output is correct
2 Correct 134 ms 348 KB Output is correct
3 Correct 137 ms 348 KB Output is correct
4 Correct 131 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 67 ms 600 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 32 ms 460 KB Output is correct
9 Correct 130 ms 444 KB Output is correct
10 Correct 164 ms 348 KB Output is correct
11 Correct 21 ms 348 KB Output is correct
12 Correct 131 ms 344 KB Output is correct
13 Runtime error 1 ms 604 KB Execution killed with signal 11
14 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 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Runtime error 0 ms 600 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -