QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#120019#4356. Giraffeslmeowdn#32 1ms4496kbC++141.9kb2023-07-06 11:00:242024-07-04 00:21:00

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 00:21:00]
  • 评测
  • 测评结果:32
  • 用时:1ms
  • 内存:4496kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 11:00:24]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii; 
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=8005;
int n,S,a[N],ans,f[15][(1<<13)+5];

signed main() {
  n=read(); ans=n; S=(1<<n)-1;
  rep(i,1,n) a[i]=read();
  memset(f,0x3f,sizeof(f));
  f[0][S]=0;
  rep(x,0,n-1) per(s,S,0) {
    int sz=popcnt(s), y=n-sz-x;
    if(y<0) continue;
    if(s==0) chmin(ans,f[x][s]);
    else {
      int mn=lowbit(s)+1, mx=topbit(s)+1;
      chmin(f[x+1][s^(1<<mn-1)],f[x][s]+(a[x+1]!=mn));
      chmin(f[x+1][s^(1<<mx-1)],f[x][s]+(a[x+1]!=mx));
      chmin(f[x][s^(1<<mn-1)],f[x][s]+(a[n-y]!=mn));
      chmin(f[x][s^(1<<mx-1)],f[x][s]+(a[n-y]!=mx));
    }
  }
  printf("%d\n",ans);
  return 0;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 1ms
memory: 4236kb

input:

1
1

output:

0

result:

ok single line: '0'

Test #2:

score: 10
Accepted
time: 1ms
memory: 4380kb

input:

2
2 1

output:

0

result:

ok single line: '0'

Test #3:

score: 10
Accepted
time: 1ms
memory: 4496kb

input:

3
1 2 3

output:

0

result:

ok single line: '0'

Test #4:

score: 10
Accepted
time: 1ms
memory: 4140kb

input:

4
3 1 4 2

output:

2

result:

ok single line: '2'

Test #5:

score: 10
Accepted
time: 1ms
memory: 4212kb

input:

5
3 4 5 1 2

output:

2

result:

ok single line: '2'

Test #6:

score: 10
Accepted
time: 1ms
memory: 4140kb

input:

6
1 5 6 2 4 3

output:

2

result:

ok single line: '2'

Test #7:

score: 10
Accepted
time: 1ms
memory: 4132kb

input:

6
1 6 3 4 2 5

output:

0

result:

ok single line: '0'

Test #8:

score: 10
Accepted
time: 0ms
memory: 4340kb

input:

7
5 3 4 6 2 7 1

output:

0

result:

ok single line: '0'

Test #9:

score: 10
Accepted
time: 0ms
memory: 4256kb

input:

7
5 3 7 1 2 6 4

output:

3

result:

ok single line: '3'

Test #10:

score: 10
Accepted
time: 1ms
memory: 4128kb

input:

7
5 2 3 6 7 1 4

output:

2

result:

ok single line: '2'

Subtask #2:

score: 22
Accepted

Test #11:

score: 22
Accepted
time: 1ms
memory: 4496kb

input:

8
7 2 1 8 3 5 4 6

output:

3

result:

ok single line: '3'

Test #12:

score: 22
Accepted
time: 1ms
memory: 4236kb

input:

9
3 1 5 6 8 4 7 9 2

output:

3

result:

ok single line: '3'

Test #13:

score: 22
Accepted
time: 1ms
memory: 4196kb

input:

10
4 6 5 7 1 2 3 8 9 10

output:

2

result:

ok single line: '2'

Test #14:

score: 22
Accepted
time: 1ms
memory: 4432kb

input:

11
2 10 3 11 1 5 8 6 4 7 9

output:

5

result:

ok single line: '5'

Test #15:

score: 22
Accepted
time: 1ms
memory: 4428kb

input:

12
2 7 3 1 9 4 8 12 11 6 5 10

output:

5

result:

ok single line: '5'

Test #16:

score: 22
Accepted
time: 0ms
memory: 4496kb

input:

12
11 7 4 10 8 3 1 9 12 6 5 2

output:

5

result:

ok single line: '5'

Test #17:

score: 22
Accepted
time: 0ms
memory: 4192kb

input:

13
11 4 8 5 9 2 3 7 13 12 1 10 6

output:

7

result:

ok single line: '7'

Test #18:

score: 22
Accepted
time: 1ms
memory: 4384kb

input:

13
6 3 10 8 13 11 4 1 7 5 12 9 2

output:

7

result:

ok single line: '7'

Test #19:

score: 22
Accepted
time: 0ms
memory: 4192kb

input:

13
11 4 8 2 7 6 5 12 10 1 13 9 3

output:

5

result:

ok single line: '5'

Test #20:

score: 22
Accepted
time: 1ms
memory: 4124kb

input:

13
4 2 6 7 11 5 3 9 10 1 8 13 12

output:

6

result:

ok single line: '6'

Subtask #3:

score: 0
Runtime Error

Test #21:

score: 0
Runtime Error

input:

29
7 22 11 16 27 1 24 12 6 21 13 2 10 8 25 15 4 19 17 9 23 5 14 20 18 28 26 29 3

output:


result:


Subtask #4:

score: 0
Runtime Error

Test #31:

score: 0
Runtime Error

input:

2317
1841 533 998 38 1358 1204 1174 176 581 1719 550 906 35 101 442 1068 1781 601 1368 2190 2095 919 2186 1134 1814 625 90 2007 653 186 204 997 1607 1675 45 806 483 299 27 935 1070 1425 1822 1712 2074 2259 264 840 1960 1045 1742 1185 577 142 980 151 2136 2143 955 462 1373 395 1300 185 637 734 803 13...

output:


result: