답안 #534858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534858 2022-03-09T04:21:35 Z Paul_Liao_1457 Group Photo (JOI21_ho_t3) C++14
12 / 100
514 ms 332 KB
// 還要更強
#include<iostream>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<math.h>
#include<cstring>
#include<stack>
#include<string.h>
#include<random>
#include<algorithm>
#include<vector>

#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define INF (ll)(1e9)
#define pb push_back
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int bit[5005],a[5005],b[5005],n,pos[5005];

void add(int x){
    for(int i=x;i>0;i-=i&(-i)) bit[i]++;
}

int ask(int x){
    int r=0;
    for(int i=x;i<=n;i+=i&(-i)){
        r+=bit[i];
    }
    return r;
}

int cnt(){
    int ans=0;
    FOR(i,1,n+1) bit[i]=0;
    FOR(i,1,n+1){
        ans+=ask(b[i]);
        add(b[i]);
    }
    return ans;
}

bool check(vector<int> v){
    FOR(i,1,n)if(v[i]+2<=v[i-1]) return 0;
    return 1;
}

signed main(){
    AC;
    int res;
    cin>>n;
    FOR(i,1,n+1){
        cin>>a[i]; pos[a[i]]=i;
    }
    FOR(i,1,n+1){
        b[i]=a[i];
    }
    res=cnt();
    FOR(s,0,(1<<n)){
        int last=0;
        vector<int> v;
        FOR(i,0,n)if(s&(1<<i)){
            int tmp=i+1;
            while(tmp!=last){
                v.pb(tmp--);
            }
            last=i+1;
        }
        FOR(i,0,v.size()) b[pos[v[i]]]=i+1;
        res=min(res,cnt());
    }
    cout<<res<<endl;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:16:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 | #define FOR(i,a,b) for(int i=a;i<b;i++)
......
   74 |         FOR(i,0,v.size()) b[pos[v[i]]]=i+1;
      |             ~~~~~~~~~~~~         
Main.cpp:74:9: note: in expansion of macro 'FOR'
   74 |         FOR(i,0,v.size()) b[pos[v[i]]]=i+1;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 121 ms 308 KB Output is correct
12 Correct 245 ms 320 KB Output is correct
13 Correct 245 ms 308 KB Output is correct
14 Correct 504 ms 312 KB Output is correct
15 Correct 514 ms 308 KB Output is correct
16 Correct 501 ms 308 KB Output is correct
17 Correct 486 ms 332 KB Output is correct
18 Correct 508 ms 308 KB Output is correct
19 Correct 496 ms 312 KB Output is correct
20 Correct 490 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 121 ms 308 KB Output is correct
12 Correct 245 ms 320 KB Output is correct
13 Correct 245 ms 308 KB Output is correct
14 Correct 504 ms 312 KB Output is correct
15 Correct 514 ms 308 KB Output is correct
16 Correct 501 ms 308 KB Output is correct
17 Correct 486 ms 332 KB Output is correct
18 Correct 508 ms 308 KB Output is correct
19 Correct 496 ms 312 KB Output is correct
20 Correct 490 ms 332 KB Output is correct
21 Incorrect 1 ms 332 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 121 ms 308 KB Output is correct
12 Correct 245 ms 320 KB Output is correct
13 Correct 245 ms 308 KB Output is correct
14 Correct 504 ms 312 KB Output is correct
15 Correct 514 ms 308 KB Output is correct
16 Correct 501 ms 308 KB Output is correct
17 Correct 486 ms 332 KB Output is correct
18 Correct 508 ms 308 KB Output is correct
19 Correct 496 ms 312 KB Output is correct
20 Correct 490 ms 332 KB Output is correct
21 Incorrect 1 ms 332 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 121 ms 308 KB Output is correct
12 Correct 245 ms 320 KB Output is correct
13 Correct 245 ms 308 KB Output is correct
14 Correct 504 ms 312 KB Output is correct
15 Correct 514 ms 308 KB Output is correct
16 Correct 501 ms 308 KB Output is correct
17 Correct 486 ms 332 KB Output is correct
18 Correct 508 ms 308 KB Output is correct
19 Correct 496 ms 312 KB Output is correct
20 Correct 490 ms 332 KB Output is correct
21 Incorrect 1 ms 332 KB Output isn't correct
22 Halted 0 ms 0 KB -