답안 #159183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
159183 2019-10-21T12:47:15 Z Bilyana Arranging Shoes (IOI19_shoes) C++17
50 / 100
110 ms 71168 KB
#include<iostream>
#include<queue>
#include<cmath>

using namespace std;

const int MAXN = 100000;
int n, to[MAXN+10];
queue<int> bs[MAXN+10];
long long counter=0;

/*void input()
{
    int temp;
    cin>>n;
    for (int i=0; i<2*n; i++)
    {
        cin>>temp;
        s.push_back(temp);
    }
}*/

void output()
{
    cout<<counter<<endl;
}

void find_place(vector<int> S)
{
    int curr = 0;
    int temp;
    for (int i=0; i<n; i++)
    {
        temp = abs(S[i]);
        if (S[i]>0)
        {
            if (!bs[temp].empty() && bs[temp].front()%2==0)
            {
                //cout<<i<<' '<<bs[temp].front()<<endl;
                to[i] = bs[temp].front()+1;
                bs[temp].pop();
            }
            else
            {
                to[i] = curr+1;
                bs[temp].push(curr+1);
                curr += 2;
            }
        }
        else
        {
            if (!bs[temp].empty() && bs[temp].front()%2==1)
            {
                to[i] = bs[temp].front()-1;
                bs[temp].pop();
            }
            else
            {
                to[i] = curr;
                bs[temp].push(curr);
                curr += 2;
            }
        }
    }
}

void sorting()
{
    for (int i=0; i<n; i++)
    {
        int nd=i;
        while (to[nd]!=i && nd<n) nd++;
        //cout<<i<<" - ";
        while (nd!=i)
        {
            //cout<<nd<<' ';
            swap(to[nd], to[nd-1]);
            counter++;
            nd--;
        }
        //cout<<endl;
    }
}

void solve(vector<int> S)
{
    n = S.size();
    find_place(S);
    sorting();
}

long long count_swaps(vector<int> S)
{
    solve(S);
    return counter;
}

/*int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    input();
    solve();
    output();
    return 0;
}*/

/*
3
-2 2 2 -2 -2 2
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 67576 KB Output is correct
2 Correct 69 ms 67652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 67576 KB Output is correct
2 Correct 69 ms 67652 KB Output is correct
3 Correct 67 ms 67716 KB Output is correct
4 Correct 67 ms 67676 KB Output is correct
5 Correct 67 ms 67576 KB Output is correct
6 Correct 68 ms 67576 KB Output is correct
7 Correct 69 ms 67576 KB Output is correct
8 Correct 67 ms 67576 KB Output is correct
9 Correct 68 ms 67704 KB Output is correct
10 Correct 68 ms 67680 KB Output is correct
11 Correct 68 ms 67704 KB Output is correct
12 Correct 67 ms 67704 KB Output is correct
13 Correct 76 ms 67708 KB Output is correct
14 Correct 69 ms 67704 KB Output is correct
15 Correct 68 ms 67704 KB Output is correct
16 Correct 73 ms 67704 KB Output is correct
17 Correct 85 ms 67576 KB Output is correct
18 Correct 69 ms 67704 KB Output is correct
19 Correct 68 ms 67608 KB Output is correct
20 Correct 69 ms 67624 KB Output is correct
21 Correct 68 ms 67676 KB Output is correct
22 Correct 68 ms 67644 KB Output is correct
23 Correct 68 ms 67576 KB Output is correct
24 Correct 67 ms 67576 KB Output is correct
25 Correct 67 ms 67576 KB Output is correct
26 Correct 67 ms 67704 KB Output is correct
27 Correct 67 ms 67676 KB Output is correct
28 Correct 66 ms 67704 KB Output is correct
29 Correct 67 ms 67576 KB Output is correct
30 Correct 67 ms 67584 KB Output is correct
31 Correct 67 ms 67792 KB Output is correct
32 Correct 67 ms 67632 KB Output is correct
33 Correct 67 ms 67624 KB Output is correct
34 Correct 67 ms 67576 KB Output is correct
35 Correct 67 ms 67596 KB Output is correct
36 Correct 69 ms 67576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 67576 KB Output is correct
2 Correct 69 ms 67652 KB Output is correct
3 Correct 67 ms 67576 KB Output is correct
4 Correct 67 ms 67580 KB Output is correct
5 Correct 71 ms 67576 KB Output is correct
6 Correct 69 ms 67648 KB Output is correct
7 Correct 68 ms 67576 KB Output is correct
8 Correct 69 ms 67604 KB Output is correct
9 Correct 68 ms 67576 KB Output is correct
10 Correct 67 ms 67704 KB Output is correct
11 Correct 78 ms 67660 KB Output is correct
12 Correct 69 ms 67580 KB Output is correct
13 Correct 70 ms 67704 KB Output is correct
14 Correct 67 ms 67580 KB Output is correct
15 Correct 67 ms 67676 KB Output is correct
16 Correct 68 ms 67708 KB Output is correct
17 Correct 67 ms 67704 KB Output is correct
18 Correct 72 ms 67704 KB Output is correct
19 Correct 71 ms 67704 KB Output is correct
20 Correct 70 ms 67960 KB Output is correct
21 Correct 72 ms 68088 KB Output is correct
22 Incorrect 109 ms 71168 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 67576 KB Output is correct
2 Correct 67 ms 67704 KB Output is correct
3 Correct 67 ms 67656 KB Output is correct
4 Correct 68 ms 67708 KB Output is correct
5 Incorrect 110 ms 71160 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 67576 KB Output is correct
2 Correct 69 ms 67652 KB Output is correct
3 Correct 67 ms 67716 KB Output is correct
4 Correct 67 ms 67676 KB Output is correct
5 Correct 67 ms 67576 KB Output is correct
6 Correct 68 ms 67576 KB Output is correct
7 Correct 69 ms 67576 KB Output is correct
8 Correct 67 ms 67576 KB Output is correct
9 Correct 68 ms 67704 KB Output is correct
10 Correct 68 ms 67680 KB Output is correct
11 Correct 68 ms 67704 KB Output is correct
12 Correct 67 ms 67704 KB Output is correct
13 Correct 76 ms 67708 KB Output is correct
14 Correct 69 ms 67704 KB Output is correct
15 Correct 68 ms 67704 KB Output is correct
16 Correct 73 ms 67704 KB Output is correct
17 Correct 85 ms 67576 KB Output is correct
18 Correct 69 ms 67704 KB Output is correct
19 Correct 68 ms 67608 KB Output is correct
20 Correct 69 ms 67624 KB Output is correct
21 Correct 68 ms 67676 KB Output is correct
22 Correct 68 ms 67644 KB Output is correct
23 Correct 68 ms 67576 KB Output is correct
24 Correct 67 ms 67576 KB Output is correct
25 Correct 67 ms 67576 KB Output is correct
26 Correct 67 ms 67704 KB Output is correct
27 Correct 67 ms 67676 KB Output is correct
28 Correct 66 ms 67704 KB Output is correct
29 Correct 67 ms 67576 KB Output is correct
30 Correct 67 ms 67584 KB Output is correct
31 Correct 67 ms 67792 KB Output is correct
32 Correct 67 ms 67632 KB Output is correct
33 Correct 67 ms 67624 KB Output is correct
34 Correct 67 ms 67576 KB Output is correct
35 Correct 67 ms 67596 KB Output is correct
36 Correct 69 ms 67576 KB Output is correct
37 Correct 67 ms 67680 KB Output is correct
38 Correct 67 ms 67832 KB Output is correct
39 Correct 68 ms 67580 KB Output is correct
40 Correct 82 ms 67704 KB Output is correct
41 Correct 70 ms 67824 KB Output is correct
42 Correct 79 ms 67704 KB Output is correct
43 Correct 80 ms 67704 KB Output is correct
44 Correct 76 ms 67620 KB Output is correct
45 Correct 77 ms 67832 KB Output is correct
46 Correct 68 ms 67664 KB Output is correct
47 Correct 69 ms 67632 KB Output is correct
48 Correct 68 ms 67704 KB Output is correct
49 Correct 69 ms 67804 KB Output is correct
50 Correct 73 ms 67692 KB Output is correct
51 Correct 73 ms 67676 KB Output is correct
52 Correct 69 ms 67832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 67576 KB Output is correct
2 Correct 69 ms 67652 KB Output is correct
3 Correct 67 ms 67716 KB Output is correct
4 Correct 67 ms 67676 KB Output is correct
5 Correct 67 ms 67576 KB Output is correct
6 Correct 68 ms 67576 KB Output is correct
7 Correct 69 ms 67576 KB Output is correct
8 Correct 67 ms 67576 KB Output is correct
9 Correct 68 ms 67704 KB Output is correct
10 Correct 68 ms 67680 KB Output is correct
11 Correct 68 ms 67704 KB Output is correct
12 Correct 67 ms 67704 KB Output is correct
13 Correct 76 ms 67708 KB Output is correct
14 Correct 69 ms 67704 KB Output is correct
15 Correct 68 ms 67704 KB Output is correct
16 Correct 73 ms 67704 KB Output is correct
17 Correct 85 ms 67576 KB Output is correct
18 Correct 69 ms 67704 KB Output is correct
19 Correct 68 ms 67608 KB Output is correct
20 Correct 69 ms 67624 KB Output is correct
21 Correct 68 ms 67676 KB Output is correct
22 Correct 68 ms 67644 KB Output is correct
23 Correct 68 ms 67576 KB Output is correct
24 Correct 67 ms 67576 KB Output is correct
25 Correct 67 ms 67576 KB Output is correct
26 Correct 67 ms 67704 KB Output is correct
27 Correct 67 ms 67676 KB Output is correct
28 Correct 66 ms 67704 KB Output is correct
29 Correct 67 ms 67576 KB Output is correct
30 Correct 67 ms 67584 KB Output is correct
31 Correct 67 ms 67792 KB Output is correct
32 Correct 67 ms 67632 KB Output is correct
33 Correct 67 ms 67624 KB Output is correct
34 Correct 67 ms 67576 KB Output is correct
35 Correct 67 ms 67596 KB Output is correct
36 Correct 69 ms 67576 KB Output is correct
37 Correct 67 ms 67576 KB Output is correct
38 Correct 67 ms 67580 KB Output is correct
39 Correct 71 ms 67576 KB Output is correct
40 Correct 69 ms 67648 KB Output is correct
41 Correct 68 ms 67576 KB Output is correct
42 Correct 69 ms 67604 KB Output is correct
43 Correct 68 ms 67576 KB Output is correct
44 Correct 67 ms 67704 KB Output is correct
45 Correct 78 ms 67660 KB Output is correct
46 Correct 69 ms 67580 KB Output is correct
47 Correct 70 ms 67704 KB Output is correct
48 Correct 67 ms 67580 KB Output is correct
49 Correct 67 ms 67676 KB Output is correct
50 Correct 68 ms 67708 KB Output is correct
51 Correct 67 ms 67704 KB Output is correct
52 Correct 72 ms 67704 KB Output is correct
53 Correct 71 ms 67704 KB Output is correct
54 Correct 70 ms 67960 KB Output is correct
55 Correct 72 ms 68088 KB Output is correct
56 Incorrect 109 ms 71168 KB Output isn't correct
57 Halted 0 ms 0 KB -