Submission #60078097


Source Code Expand

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <atcoder/all>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, l, r) for (int i = l; i <= r; i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<VI>;
using VVL = vector<VL>;

const int INF = 1e9;

int main()
{
    int n, m = 20;
    cin >> n;
    VI a(n);
    VVI pos(m);
    REP(i,n){
        cin >> a[i];
        a[i]--;
        pos[a[i]].push_back(i);
    }
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push({0, 0});
    VI dist(1<<m, INF);
    dist[0] = 0;
    while(!pq.empty()){
        auto [d, b] = pq.top(); pq.pop();
        if(dist[b] < d) continue;
        REP(i,m){
            if ((b>>i)&1) continue;
            int x = lower_bound(pos[i].begin(), pos[i].end(), d) - pos[i].begin();
            if (x + 1 >= pos[i].size()) continue;
            int nb = b | (1<<i);
            int nd = pos[i][x+1];
            if (dist[nb] > nd){
                dist[nb] = nd;
                pq.push({nd, nb});
            }
        }
    }
    int ans = 0;
    REP(i,1<<m) {
        if (dist[i] < INF) {
            int cnt = 0;
            REP(j,m) if ((i>>j)&1) cnt++;
            chmax(ans, cnt);
        }
    }
    cout << 2*ans << endl;
    return 0;
}

Submission Info

Submission Time
Task F - 1122 Subsequence
User TangentDay
Language C++ 20 (gcc 12.2)
Score 525
Code Size 1552 Byte
Status AC
Exec Time 527 ms
Memory 16748 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:45:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   45 |             if (x + 1 >= pos[i].size()) continue;
      |                 ~~~~~~^~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 2
AC × 46
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt
Case Name Status Exec Time Memory
example_00.txt AC 3 ms 7376 KiB
example_01.txt AC 3 ms 7372 KiB
hand_00.txt AC 180 ms 11560 KiB
hand_01.txt AC 229 ms 9520 KiB
hand_02.txt AC 231 ms 9352 KiB
hand_03.txt AC 234 ms 9520 KiB
hand_04.txt AC 244 ms 9504 KiB
hand_05.txt AC 24 ms 9184 KiB
hand_06.txt AC 24 ms 9032 KiB
hand_07.txt AC 3 ms 7456 KiB
hand_08.txt AC 3 ms 7484 KiB
random_00.txt AC 333 ms 11428 KiB
random_01.txt AC 304 ms 11696 KiB
random_02.txt AC 467 ms 15716 KiB
random_03.txt AC 385 ms 11484 KiB
random_04.txt AC 527 ms 15716 KiB
random_05.txt AC 521 ms 15712 KiB
random_06.txt AC 255 ms 12536 KiB
random_07.txt AC 259 ms 12496 KiB
random_08.txt AC 42 ms 8724 KiB
random_09.txt AC 254 ms 12620 KiB
random_10.txt AC 257 ms 12420 KiB
random_11.txt AC 252 ms 12268 KiB
random_12.txt AC 67 ms 9092 KiB
random_13.txt AC 152 ms 10484 KiB
random_14.txt AC 264 ms 12324 KiB
random_15.txt AC 19 ms 8060 KiB
random_16.txt AC 147 ms 10324 KiB
random_17.txt AC 280 ms 12556 KiB
random_18.txt AC 277 ms 12388 KiB
random_19.txt AC 299 ms 12408 KiB
random_20.txt AC 328 ms 12508 KiB
random_21.txt AC 102 ms 10512 KiB
random_22.txt AC 16 ms 8204 KiB
random_23.txt AC 255 ms 16580 KiB
random_24.txt AC 344 ms 12516 KiB
random_25.txt AC 86 ms 10428 KiB
random_26.txt AC 171 ms 12432 KiB
random_27.txt AC 76 ms 10420 KiB
random_28.txt AC 28 ms 8820 KiB
random_29.txt AC 75 ms 10516 KiB
random_30.txt AC 67 ms 10484 KiB
random_31.txt AC 405 ms 16748 KiB
random_32.txt AC 29 ms 8772 KiB
random_33.txt AC 182 ms 12508 KiB
random_34.txt AC 47 ms 9364 KiB