답안 #1110789

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110789 2024-11-10T13:30:39 Z epicci23 Arranging Shoes (IOI19_shoes) C++17
30 / 100
1000 ms 142792 KB
#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)x.size()
 
struct Fenwick{
  vector<int64_t> fw;
  int N;
  Fenwick(int64_t _n){
  	N = _n + 15;
  	fw.assign(N,0);
  }
  void upd(int64_t c){
    for(;c<N;c+=c&-c) fw[c]++;
  }
  int64_t query(int64_t c,int64_t res=0){
  	for(;c;c-=c&-c) res+=fw[c];
  	return res;
  }
};
 
int64_t count_swaps(vector<int> S){
  int64_t n , ans = 0; 
  n = sz(S) / 2;
  int64_t ar[2 * n + 5];
  for(int i=1;i<=2*n;i++) ar[i] = S[i - 1];
 
  if(n<=8){

  	vector<int64_t> xd;
  	for(int i=1;i<=2*n;i++) if(ar[i]<0) xd.push_back(-ar[i]);
    sort(all(xd));
    int64_t res = (int)1e9;

    do{

      int64_t hm = 0, p = 1;
      queue<int64_t> q1[n+5];
      queue<int64_t> q2[n+5];

      for(int i=1;i<=2*n;i++){
      	if(ar[i]<0) q1[-ar[i]].push(i);
      	else q2[ar[i]].push(i);
      }

      Fenwick F(2*n);
      for(int u:xd){
       int64_t c = q1[u].front();
  	   q1[u].pop();
  	   int64_t x = q2[u].front();
  	   q2[u].pop();

  	   F.upd(c);
       c+=F.query(2*n)-F.query(c);
       hm+=c-p;
       p++;

       F.upd(x);
       x+=F.query(2*n)-F.query(x);
       hm+=x-p;
       p++;
      }
      res=min(res,hm);
    }while(next_permutation(all(xd)));

    return res;
  }

  /*int p = 1;
  while(!q.empty()){
  	int64_t c = q.front();
  	q.pop();
  	int64_t x = pos[-ar[c]].back();
  	pos[-ar[c]].pop_back();

  	F.upd(c);
    c+=F.query(2*n)-F.query(c);
    ans+=c-p;
    p++;

    F.upd(x);
    x+=F.query(2*n)-F.query(x);
    ans+=x-p;
    p++;
  }
 
  return ans;*/
}
 
 
/*void _(){
  int n,ans=0; cin >> n;
  int ar[2*n+5];
  for(int i=1;i<=2*n;i++) cin >> ar[i];
  
  queue<int> q;
  vector<int> pos[n+5];
 
  Fenwick F(2*n);
 
  for(int i=1;i<=2*n;i++){
    if(ar[i]<0) q.push(i);
    else pos[ar[i]].push_back(i);
  }
  
  for(int i=1;i<=n;i++) reverse(all(pos[i]));
 
  int p = 1;
  while(!q.empty()){
  	int64_t c = q.front();
  	q.pop();
  	int64_t x = pos[-ar[c]].back();
  	pos[-ar[c]].pop_back();

  	F.upd(c);
    c+=F.query(2*n)-F.query(c);
    ans+=c-p;
    p++;

    F.upd(x);
    x+=F.query(2*n)-F.query(x);
    ans+=x-p;
    p++;
  }
 
  cout << ans << '\n';
}
 
int32_t main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tc=1;//cin >> tc;
  while(tc--) _();
}*/

Compilation message

shoes.cpp: In function 'int64_t count_swaps(std::vector<int>)':
shoes.cpp:24:15: warning: unused variable 'ans' [-Wunused-variable]
   24 |   int64_t n , ans = 0;
      |               ^~~
shoes.cpp:89:1: warning: control reaches end of non-void function [-Wreturn-type]
   89 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 504 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 4 ms 336 KB Output is correct
26 Correct 48 ms 336 KB Output is correct
27 Correct 24 ms 336 KB Output is correct
28 Correct 23 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 6 ms 336 KB Output is correct
34 Correct 13 ms 336 KB Output is correct
35 Correct 5 ms 336 KB Output is correct
36 Correct 22 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 848 KB Output is correct
18 Correct 2 ms 1616 KB Output is correct
19 Correct 3 ms 1616 KB Output is correct
20 Correct 16 ms 14428 KB Output is correct
21 Correct 15 ms 14532 KB Output is correct
22 Correct 155 ms 142128 KB Output is correct
23 Correct 167 ms 142012 KB Output is correct
24 Correct 151 ms 142012 KB Output is correct
25 Incorrect 161 ms 142792 KB Output isn't correct
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Execution timed out 1080 ms 140388 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 504 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 4 ms 336 KB Output is correct
26 Correct 48 ms 336 KB Output is correct
27 Correct 24 ms 336 KB Output is correct
28 Correct 23 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 6 ms 336 KB Output is correct
34 Correct 13 ms 336 KB Output is correct
35 Correct 5 ms 336 KB Output is correct
36 Correct 22 ms 448 KB Output is correct
37 Execution timed out 1046 ms 336 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 504 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 4 ms 336 KB Output is correct
26 Correct 48 ms 336 KB Output is correct
27 Correct 24 ms 336 KB Output is correct
28 Correct 23 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 6 ms 336 KB Output is correct
34 Correct 13 ms 336 KB Output is correct
35 Correct 5 ms 336 KB Output is correct
36 Correct 22 ms 448 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 1 ms 336 KB Output is correct
50 Correct 1 ms 592 KB Output is correct
51 Correct 1 ms 848 KB Output is correct
52 Correct 2 ms 1616 KB Output is correct
53 Correct 3 ms 1616 KB Output is correct
54 Correct 16 ms 14428 KB Output is correct
55 Correct 15 ms 14532 KB Output is correct
56 Correct 155 ms 142128 KB Output is correct
57 Correct 167 ms 142012 KB Output is correct
58 Correct 151 ms 142012 KB Output is correct
59 Incorrect 161 ms 142792 KB Output isn't correct
60 Halted 0 ms 0 KB -