답안 #159181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
159181 2019-10-21T12:43:55 Z Mathew Arranging Shoes (IOI19_shoes) C++14
0 / 100
6 ms 3848 KB
#include<bits/stdc++.h>
using namespace std;

long long n,to[2500],pairs=0,br=0;
queue <long long> found[2500];
long long from[2500],perm[2500];

long long count_swaps(vector <int> shoes)
{
    long long i,j;
    n=shoes.size();
    for(i=0;i<2*n;i++)perm[i]=i;
    for(i=0;i<2*n;i++)
    {
        if(shoes[i]<0)
        {
            if(found[shoes[i]+n].empty()==false)
            {
                to[i]=found[shoes[i]+n].front();
                found[shoes[i]+n].pop();
            }
            else
            {
                to[i]=pairs;
                found[n-shoes[i]].push(pairs+1);
                pairs+=2;
            }
        }
        
        else
        {
            if(found[shoes[i]+n].empty()==false)
            {
                to[i]=found[shoes[i]+n].front();
                found[shoes[i]+n].pop();
            }
            else
            {
                to[i]=pairs+1;
                found[n-shoes[i]].push(pairs);
                pairs+=2;
            }
        }
    }
    
    for(i=0;i<2*n;i++)from[to[i]]=i;
    
    //for(i=0;i<2*n;i++)cout<<to[i]<<' ';cout<<endl;
    //for(i=0;i<2*n;i++)cout<<from[i]<<' ';cout<<endl;
    
    for(i=0;i<2*n;i++)
    {
        for(j=0;j<perm[from[i]];j++)
        {
            perm[j]++;
        }
        br+=abs(i-perm[from[i]]);
    }
    cout<<br/2<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 3832 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 3832 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 3832 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 3848 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 3832 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 3832 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -