Submission #159182

# Submission time Handle Problem Language Result Execution time Memory
159182 2019-10-21T12:45:20 Z Bilyana Arranging Shoes (IOI19_shoes) C++17
50 / 100
214 ms 138464 KB
#include<iostream>
#include<queue>
#include<cmath>

using namespace std;

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

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

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

void find_place(vector<int> S)
{
    long long curr = 0;
    long long temp;
    for (long long 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 (long long i=0; i<n; i++)
    {
        long long 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;
}

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

/*
3
-2 2 2 -2 -2 2
*/
# Verdict Execution time Memory Grader output
1 Correct 68 ms 67576 KB Output is correct
2 Correct 68 ms 67576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 67576 KB Output is correct
2 Correct 68 ms 67576 KB Output is correct
3 Correct 67 ms 67704 KB Output is correct
4 Correct 69 ms 67568 KB Output is correct
5 Correct 67 ms 67704 KB Output is correct
6 Correct 67 ms 67576 KB Output is correct
7 Correct 67 ms 67640 KB Output is correct
8 Correct 66 ms 67548 KB Output is correct
9 Correct 68 ms 67640 KB Output is correct
10 Correct 68 ms 67664 KB Output is correct
11 Correct 68 ms 67576 KB Output is correct
12 Correct 69 ms 67704 KB Output is correct
13 Correct 68 ms 67700 KB Output is correct
14 Correct 68 ms 67748 KB Output is correct
15 Correct 68 ms 67576 KB Output is correct
16 Correct 72 ms 67688 KB Output is correct
17 Correct 68 ms 67576 KB Output is correct
18 Correct 67 ms 67704 KB Output is correct
19 Correct 68 ms 67628 KB Output is correct
20 Correct 68 ms 67728 KB Output is correct
21 Correct 68 ms 67704 KB Output is correct
22 Correct 68 ms 67568 KB Output is correct
23 Correct 69 ms 67576 KB Output is correct
24 Correct 68 ms 67624 KB Output is correct
25 Correct 67 ms 67576 KB Output is correct
26 Correct 67 ms 67576 KB Output is correct
27 Correct 67 ms 67576 KB Output is correct
28 Correct 69 ms 67604 KB Output is correct
29 Correct 68 ms 67704 KB Output is correct
30 Correct 69 ms 67652 KB Output is correct
31 Correct 67 ms 67576 KB Output is correct
32 Correct 66 ms 67704 KB Output is correct
33 Correct 68 ms 67676 KB Output is correct
34 Correct 68 ms 67576 KB Output is correct
35 Correct 80 ms 67576 KB Output is correct
36 Correct 70 ms 67704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 67576 KB Output is correct
2 Correct 68 ms 67576 KB Output is correct
3 Correct 67 ms 67576 KB Output is correct
4 Correct 67 ms 67704 KB Output is correct
5 Correct 68 ms 67676 KB Output is correct
6 Correct 68 ms 67576 KB Output is correct
7 Correct 68 ms 67576 KB Output is correct
8 Correct 68 ms 67716 KB Output is correct
9 Correct 67 ms 67676 KB Output is correct
10 Correct 67 ms 67704 KB Output is correct
11 Correct 68 ms 67708 KB Output is correct
12 Correct 69 ms 67704 KB Output is correct
13 Correct 67 ms 67704 KB Output is correct
14 Correct 68 ms 67704 KB Output is correct
15 Correct 68 ms 67596 KB Output is correct
16 Correct 75 ms 67704 KB Output is correct
17 Correct 68 ms 67668 KB Output is correct
18 Correct 73 ms 67704 KB Output is correct
19 Correct 75 ms 67672 KB Output is correct
20 Correct 76 ms 68088 KB Output is correct
21 Correct 78 ms 68060 KB Output is correct
22 Runtime error 214 ms 138464 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 71 ms 67672 KB Output is correct
2 Correct 67 ms 67708 KB Output is correct
3 Correct 68 ms 67704 KB Output is correct
4 Correct 67 ms 67704 KB Output is correct
5 Incorrect 111 ms 71544 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 67576 KB Output is correct
2 Correct 68 ms 67576 KB Output is correct
3 Correct 67 ms 67704 KB Output is correct
4 Correct 69 ms 67568 KB Output is correct
5 Correct 67 ms 67704 KB Output is correct
6 Correct 67 ms 67576 KB Output is correct
7 Correct 67 ms 67640 KB Output is correct
8 Correct 66 ms 67548 KB Output is correct
9 Correct 68 ms 67640 KB Output is correct
10 Correct 68 ms 67664 KB Output is correct
11 Correct 68 ms 67576 KB Output is correct
12 Correct 69 ms 67704 KB Output is correct
13 Correct 68 ms 67700 KB Output is correct
14 Correct 68 ms 67748 KB Output is correct
15 Correct 68 ms 67576 KB Output is correct
16 Correct 72 ms 67688 KB Output is correct
17 Correct 68 ms 67576 KB Output is correct
18 Correct 67 ms 67704 KB Output is correct
19 Correct 68 ms 67628 KB Output is correct
20 Correct 68 ms 67728 KB Output is correct
21 Correct 68 ms 67704 KB Output is correct
22 Correct 68 ms 67568 KB Output is correct
23 Correct 69 ms 67576 KB Output is correct
24 Correct 68 ms 67624 KB Output is correct
25 Correct 67 ms 67576 KB Output is correct
26 Correct 67 ms 67576 KB Output is correct
27 Correct 67 ms 67576 KB Output is correct
28 Correct 69 ms 67604 KB Output is correct
29 Correct 68 ms 67704 KB Output is correct
30 Correct 69 ms 67652 KB Output is correct
31 Correct 67 ms 67576 KB Output is correct
32 Correct 66 ms 67704 KB Output is correct
33 Correct 68 ms 67676 KB Output is correct
34 Correct 68 ms 67576 KB Output is correct
35 Correct 80 ms 67576 KB Output is correct
36 Correct 70 ms 67704 KB Output is correct
37 Correct 67 ms 67724 KB Output is correct
38 Correct 67 ms 67704 KB Output is correct
39 Correct 67 ms 67704 KB Output is correct
40 Correct 67 ms 67668 KB Output is correct
41 Correct 68 ms 67704 KB Output is correct
42 Correct 68 ms 67676 KB Output is correct
43 Correct 67 ms 67704 KB Output is correct
44 Correct 69 ms 67704 KB Output is correct
45 Correct 69 ms 67752 KB Output is correct
46 Correct 67 ms 67704 KB Output is correct
47 Correct 69 ms 67704 KB Output is correct
48 Correct 70 ms 67704 KB Output is correct
49 Correct 69 ms 67704 KB Output is correct
50 Correct 75 ms 67636 KB Output is correct
51 Correct 73 ms 67704 KB Output is correct
52 Correct 82 ms 67852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 67576 KB Output is correct
2 Correct 68 ms 67576 KB Output is correct
3 Correct 67 ms 67704 KB Output is correct
4 Correct 69 ms 67568 KB Output is correct
5 Correct 67 ms 67704 KB Output is correct
6 Correct 67 ms 67576 KB Output is correct
7 Correct 67 ms 67640 KB Output is correct
8 Correct 66 ms 67548 KB Output is correct
9 Correct 68 ms 67640 KB Output is correct
10 Correct 68 ms 67664 KB Output is correct
11 Correct 68 ms 67576 KB Output is correct
12 Correct 69 ms 67704 KB Output is correct
13 Correct 68 ms 67700 KB Output is correct
14 Correct 68 ms 67748 KB Output is correct
15 Correct 68 ms 67576 KB Output is correct
16 Correct 72 ms 67688 KB Output is correct
17 Correct 68 ms 67576 KB Output is correct
18 Correct 67 ms 67704 KB Output is correct
19 Correct 68 ms 67628 KB Output is correct
20 Correct 68 ms 67728 KB Output is correct
21 Correct 68 ms 67704 KB Output is correct
22 Correct 68 ms 67568 KB Output is correct
23 Correct 69 ms 67576 KB Output is correct
24 Correct 68 ms 67624 KB Output is correct
25 Correct 67 ms 67576 KB Output is correct
26 Correct 67 ms 67576 KB Output is correct
27 Correct 67 ms 67576 KB Output is correct
28 Correct 69 ms 67604 KB Output is correct
29 Correct 68 ms 67704 KB Output is correct
30 Correct 69 ms 67652 KB Output is correct
31 Correct 67 ms 67576 KB Output is correct
32 Correct 66 ms 67704 KB Output is correct
33 Correct 68 ms 67676 KB Output is correct
34 Correct 68 ms 67576 KB Output is correct
35 Correct 80 ms 67576 KB Output is correct
36 Correct 70 ms 67704 KB Output is correct
37 Correct 67 ms 67576 KB Output is correct
38 Correct 67 ms 67704 KB Output is correct
39 Correct 68 ms 67676 KB Output is correct
40 Correct 68 ms 67576 KB Output is correct
41 Correct 68 ms 67576 KB Output is correct
42 Correct 68 ms 67716 KB Output is correct
43 Correct 67 ms 67676 KB Output is correct
44 Correct 67 ms 67704 KB Output is correct
45 Correct 68 ms 67708 KB Output is correct
46 Correct 69 ms 67704 KB Output is correct
47 Correct 67 ms 67704 KB Output is correct
48 Correct 68 ms 67704 KB Output is correct
49 Correct 68 ms 67596 KB Output is correct
50 Correct 75 ms 67704 KB Output is correct
51 Correct 68 ms 67668 KB Output is correct
52 Correct 73 ms 67704 KB Output is correct
53 Correct 75 ms 67672 KB Output is correct
54 Correct 76 ms 68088 KB Output is correct
55 Correct 78 ms 68060 KB Output is correct
56 Runtime error 214 ms 138464 KB Execution killed with signal 11 (could be triggered by violating memory limits)
57 Halted 0 ms 0 KB -