제출 #1343721

#제출 시각아이디문제언어결과실행 시간메모리
1343721dex111222333444555Group Photo (JOI21_ho_t3)C++20
12 / 100
286 ms181016 KiB
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
#define siz(v) ((int)(v).size())
#define all(v) begin((v)), end(v)
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define dbg(x) "[" #x " = " << x << "]"
#define lli pair<long long, int>
#define left __left
#define right __right

using namespace std;

bool M1;
const int MAXN = 5005, MAXK = 16, LOG = 20, infINT = 1e9 + 23737;
const long long inf = 1e18;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;}
template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;}


int numVal, val[MAXN], pos[MAXN];

void input(){
    cin >> numVal;
    for(int i = 0; i < numVal; i++) cin >> val[i], pos[val[i]] = i;
}

namespace sub2{
    bool checkSub(){
        return 1;
    }
    int dp[MASK(21) + 1][22];

    string binary(const int &mask){
        string s = "";
        for(int i = 0; i < numVal; i++) s += (BIT(mask, i) + '0');
        return s;
    }

    void solve(){
        memset(dp, 0x3f, sizeof dp);

        for(int i = 0; i < numVal; i++) dp[MASK(i)][val[i]] = i;

        for(int mask = 1; mask < MASK(numVal); mask++){
            int cur = __builtin_popcount(mask);

            for(int j = 1; j <= numVal; j++) if (!BIT(mask, pos[j])){
                int ncur = pos[j];
                for(int k = pos[j] + 1; k < numVal; k++) if (BIT(mask, k)) ncur++;

                for(int i = 1; i <= j + 1; i++) if (dp[mask][i] < infINT){
                    minimize(dp[mask | MASK(pos[j])][j], dp[mask][i] + (ncur - cur));
                }
            }
        }

        int best = infINT;
        for(int i = 1; i <= numVal; i++) minimize(best, dp[MASK(numVal) - 1][i]);
        cout << best << '\n';
    }
}

bool M2;
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int t = 1;
    // cin >> t;
    while(t--){
        input();
        if (sub2::checkSub()) sub2::solve();
    }
    cerr << TIME << ".s\n";
    cerr << (&M2 - &M1) / 1048576 << " MB\n";
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...