답안 #46693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46693 2018-04-22T15:05:49 Z qoo2p5 Rope (JOI17_rope) C++17
15 / 100
165 ms 924 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = (int) 1e9 + 1e6 + 123;
const ll LINF = (ll) 1e18 + 1e9 + 123;

#define rep(i, s, t) for (auto i = (s); i < (t); ++(i))
#define per(i, s, t) for (auto i = (s); i >= (t); --(i))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define mp make_pair
#define pb push_back

bool mini(auto &x, const auto &y) {
    if (y < x) {
        x = y;
        return 1;
    }
    return 0;
}

bool maxi(auto &x, const auto &y) {
    if (y > x) {
        x = y;
        return 1;
    }
    return 0;
}

void run();

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
    return 0;
}

const int N = 20;
const int M = 20;

int n, m;
int a[N];

bool test(int mask, int bit) {
    return mask & (1 << bit);
}

bool ok(vector<int> &x) {
    rep(i, 1, sz(x)) {
        if ((x[i] - x[i - 1]) % 2 == 0) {
            return 0;
        }
    }
    
    return 1;
}

void run() {
    cin >> n >> m;
    rep(i, 0, n) {
        cin >> a[i];
        a[i]--;
    }
    
    rep(c, 0, m) {
        int ans = INF;
        
        rep(mask, 1, (1 << n) - 1) {
            vector<int> x, y;
            rep(bit, 0, n) {
                if (test(mask, bit)) {
                    x.pb(bit);
                } else {
                    y.pb(bit);
                }
            }
            if (!ok(x) || !ok(y)) {
                continue;
            }
            
            int cnt_c = 0;
            for (int p : x) {
                if (a[p] == c) {
                    cnt_c++;
                }
            }
            
            if (!cnt_c) {
                continue;
            }
            
            vector<int> wow(m);
            for (int p : y) {
                wow[a[p]]++;
            }
            int kek = *max_element(all(wow));
            
            mini(ans, sz(x) - cnt_c + sz(y) - kek);
        }
        
        cout << ans << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 376 KB Output is correct
2 Correct 20 ms 376 KB Output is correct
3 Correct 40 ms 436 KB Output is correct
4 Correct 64 ms 564 KB Output is correct
5 Correct 25 ms 564 KB Output is correct
6 Correct 57 ms 572 KB Output is correct
7 Correct 75 ms 704 KB Output is correct
8 Correct 114 ms 704 KB Output is correct
9 Correct 101 ms 704 KB Output is correct
10 Correct 89 ms 880 KB Output is correct
11 Correct 6 ms 880 KB Output is correct
12 Correct 6 ms 880 KB Output is correct
13 Correct 5 ms 880 KB Output is correct
14 Correct 3 ms 880 KB Output is correct
15 Correct 2 ms 880 KB Output is correct
16 Correct 3 ms 880 KB Output is correct
17 Correct 6 ms 908 KB Output is correct
18 Correct 5 ms 908 KB Output is correct
19 Correct 5 ms 908 KB Output is correct
20 Correct 5 ms 908 KB Output is correct
21 Correct 2 ms 920 KB Output is correct
22 Correct 2 ms 924 KB Output is correct
23 Correct 2 ms 924 KB Output is correct
24 Correct 2 ms 924 KB Output is correct
25 Correct 2 ms 924 KB Output is correct
26 Correct 2 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 376 KB Output is correct
2 Correct 20 ms 376 KB Output is correct
3 Correct 40 ms 436 KB Output is correct
4 Correct 64 ms 564 KB Output is correct
5 Correct 25 ms 564 KB Output is correct
6 Correct 57 ms 572 KB Output is correct
7 Correct 75 ms 704 KB Output is correct
8 Correct 114 ms 704 KB Output is correct
9 Correct 101 ms 704 KB Output is correct
10 Correct 89 ms 880 KB Output is correct
11 Correct 6 ms 880 KB Output is correct
12 Correct 6 ms 880 KB Output is correct
13 Correct 5 ms 880 KB Output is correct
14 Correct 3 ms 880 KB Output is correct
15 Correct 2 ms 880 KB Output is correct
16 Correct 3 ms 880 KB Output is correct
17 Correct 6 ms 908 KB Output is correct
18 Correct 5 ms 908 KB Output is correct
19 Correct 5 ms 908 KB Output is correct
20 Correct 5 ms 908 KB Output is correct
21 Correct 2 ms 920 KB Output is correct
22 Correct 2 ms 924 KB Output is correct
23 Correct 2 ms 924 KB Output is correct
24 Correct 2 ms 924 KB Output is correct
25 Correct 2 ms 924 KB Output is correct
26 Correct 2 ms 924 KB Output is correct
27 Incorrect 2 ms 924 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 376 KB Output is correct
2 Correct 20 ms 376 KB Output is correct
3 Correct 40 ms 436 KB Output is correct
4 Correct 64 ms 564 KB Output is correct
5 Correct 25 ms 564 KB Output is correct
6 Correct 57 ms 572 KB Output is correct
7 Correct 75 ms 704 KB Output is correct
8 Correct 114 ms 704 KB Output is correct
9 Correct 101 ms 704 KB Output is correct
10 Correct 89 ms 880 KB Output is correct
11 Correct 6 ms 880 KB Output is correct
12 Correct 6 ms 880 KB Output is correct
13 Correct 5 ms 880 KB Output is correct
14 Correct 3 ms 880 KB Output is correct
15 Correct 2 ms 880 KB Output is correct
16 Correct 3 ms 880 KB Output is correct
17 Correct 6 ms 908 KB Output is correct
18 Correct 5 ms 908 KB Output is correct
19 Correct 5 ms 908 KB Output is correct
20 Correct 5 ms 908 KB Output is correct
21 Correct 2 ms 920 KB Output is correct
22 Correct 2 ms 924 KB Output is correct
23 Correct 2 ms 924 KB Output is correct
24 Correct 2 ms 924 KB Output is correct
25 Correct 2 ms 924 KB Output is correct
26 Correct 2 ms 924 KB Output is correct
27 Incorrect 2 ms 924 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 376 KB Output is correct
2 Correct 20 ms 376 KB Output is correct
3 Correct 40 ms 436 KB Output is correct
4 Correct 64 ms 564 KB Output is correct
5 Correct 25 ms 564 KB Output is correct
6 Correct 57 ms 572 KB Output is correct
7 Correct 75 ms 704 KB Output is correct
8 Correct 114 ms 704 KB Output is correct
9 Correct 101 ms 704 KB Output is correct
10 Correct 89 ms 880 KB Output is correct
11 Correct 6 ms 880 KB Output is correct
12 Correct 6 ms 880 KB Output is correct
13 Correct 5 ms 880 KB Output is correct
14 Correct 3 ms 880 KB Output is correct
15 Correct 2 ms 880 KB Output is correct
16 Correct 3 ms 880 KB Output is correct
17 Correct 6 ms 908 KB Output is correct
18 Correct 5 ms 908 KB Output is correct
19 Correct 5 ms 908 KB Output is correct
20 Correct 5 ms 908 KB Output is correct
21 Correct 2 ms 920 KB Output is correct
22 Correct 2 ms 924 KB Output is correct
23 Correct 2 ms 924 KB Output is correct
24 Correct 2 ms 924 KB Output is correct
25 Correct 2 ms 924 KB Output is correct
26 Correct 2 ms 924 KB Output is correct
27 Incorrect 2 ms 924 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 376 KB Output is correct
2 Correct 20 ms 376 KB Output is correct
3 Correct 40 ms 436 KB Output is correct
4 Correct 64 ms 564 KB Output is correct
5 Correct 25 ms 564 KB Output is correct
6 Correct 57 ms 572 KB Output is correct
7 Correct 75 ms 704 KB Output is correct
8 Correct 114 ms 704 KB Output is correct
9 Correct 101 ms 704 KB Output is correct
10 Correct 89 ms 880 KB Output is correct
11 Correct 6 ms 880 KB Output is correct
12 Correct 6 ms 880 KB Output is correct
13 Correct 5 ms 880 KB Output is correct
14 Correct 3 ms 880 KB Output is correct
15 Correct 2 ms 880 KB Output is correct
16 Correct 3 ms 880 KB Output is correct
17 Correct 6 ms 908 KB Output is correct
18 Correct 5 ms 908 KB Output is correct
19 Correct 5 ms 908 KB Output is correct
20 Correct 5 ms 908 KB Output is correct
21 Correct 2 ms 920 KB Output is correct
22 Correct 2 ms 924 KB Output is correct
23 Correct 2 ms 924 KB Output is correct
24 Correct 2 ms 924 KB Output is correct
25 Correct 2 ms 924 KB Output is correct
26 Correct 2 ms 924 KB Output is correct
27 Incorrect 2 ms 924 KB Output isn't correct
28 Halted 0 ms 0 KB -