QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#39948#4356. GiraffesZeinDaner0 129ms3624kbC++991b2022-07-15 05:41:242022-07-15 05:41:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-15 05:41:25]
  • 评测
  • 测评结果:0
  • 用时:129ms
  • 内存:3624kb
  • [2022-07-15 05:41:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> x,bc;
int n; 
int mincost(int id){
  if(id+3>=n){
    int c=0;
    for(int i=0;i<n;i++){
      c+=(x[i]!=bc[i]);
    }
    return c;
  }
  int mi=x[id+1],ma=x[id+1];
  int ii=id+1,ia=id+1;
  int ans=1e9;
  bool ok=0;
  for(int j=id+1;j<n;j++){
    if(j!=n-1){
      if(mi>x[j]){
	ii=j; mi=x[j];
      }
      if(ma<x[j]){
	ia=j; ma=x[j];
      }
    }
    if(x[id]<ma && x[j]<ma && x[id]>mi && x[j]>mi){
      ok=1;
    }
  }
  if(ok){
    swap(x[ii],x[id]);
    ans=min(ans,mincost(id+1));
    swap(x[ii],x[id]);
      
    swap(x[ia],x[id]);
    ans=min(ans,mincost(id+1));
    swap(x[ia],x[id]);
  }
  else ans=mincost(id+1);
  return ans;
 
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin>>n;
  for(int i=0;i<n;i++){
    int a; cin>>a;
    x.push_back(a);
    bc.push_back(a);
  }
  cout<<mincost(0)<<endl;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 2ms
memory: 3536kb

input:

1
1

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3604kb

input:

2
2 1

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3448kb

input:

3
1 2 3

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3520kb

input:

4
3 1 4 2

output:

2

result:

ok single line: '2'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3536kb

input:

5
3 4 5 1 2

output:

2

result:

ok single line: '2'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

6
1 5 6 2 4 3

output:

2

result:

ok single line: '2'

Test #7:

score: 0
Accepted
time: 2ms
memory: 3588kb

input:

6
1 6 3 4 2 5

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 2ms
memory: 3548kb

input:

7
5 3 4 6 2 7 1

output:

0

result:

ok single line: '0'

Test #9:

score: -10
Wrong Answer
time: 0ms
memory: 3624kb

input:

7
5 3 7 1 2 6 4

output:

4

result:

wrong answer 1st lines differ - expected: '3', found: '4'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 22
Accepted
time: 2ms
memory: 3424kb

input:

8
7 2 1 8 3 5 4 6

output:

3

result:

ok single line: '3'

Test #12:

score: -22
Wrong Answer
time: 2ms
memory: 3556kb

input:

9
3 1 5 6 8 4 7 9 2

output:

4

result:

wrong answer 1st lines differ - expected: '3', found: '4'

Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 129ms
memory: 3620kb

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:

21

result:

wrong answer 1st lines differ - expected: '17', found: '21'

Subtask #4:

score: 0
Time Limit Exceeded

Test #31:

score: 0
Time Limit Exceeded

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: