Submission #3433350


Source Code Expand

#include <bits/stdc++.h>
#define oo 500005
using namespace std;
int n, a[oo], p[oo], k;
int main ()
{
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; ++ i)
    scanf("%d", &a[i]), p[a[i]] = i;
    for(int i = 1; i <= n; ++ i)
    {
        while(a[i] != 1)
        {
            if(p[a[i] - 1] - p[a[i]] >= k)
            {
                int p1 = p[a[i] - 1];
                swap(p[a[i] - 1], p[a[i]]);
                swap(a[i], a[p1]);
                continue;
            }
            if(a[i] > 2 && p[a[i] - 1] > p[a[i]] && p[a[i] - 2] - p[a[i] - 1] >= k)
            {
                int p1 = p[a[i] - 1], p2 = p[a[i] - 2];
                swap(p[a[i] - 1], p[a[i] - 2]);
                swap(a[p1], a[p2]);
                p1 = p[a[i] - 1];
                swap(p[a[i] - 1], p[a[i]]);
                swap(a[i], a[p1]);
                continue;
            }
            break;
        }
    }
    for(int i = 1; i <= n; ++ i)
    printf("%d\n", a[i]); return 0;
}

Submission Info

Submission Time
Task F - Wide Swap
User poilog
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1018 Byte
Status WA
Exec Time 5256 ms
Memory 7424 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:7:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
                          ^
./Main.cpp:9:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &a[i]), p[a[i]] = i;
                                    ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 2000
Status
AC × 3
AC × 40
WA × 44
TLE × 10
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, 059.txt, 060.txt, 061.txt, 062.txt, 063.txt, 064.txt, 065.txt, 066.txt, 067.txt, 068.txt, 069.txt, 070.txt, 071.txt, 072.txt, 073.txt, 074.txt, 075.txt, 076.txt, 077.txt, 078.txt, 079.txt, 080.txt, 081.txt, 082.txt, 083.txt, 084.txt, 085.txt, 086.txt, 087.txt, 088.txt, 089.txt, 090.txt, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
000.txt AC 1 ms 256 KB
001.txt AC 1 ms 256 KB
002.txt AC 1 ms 256 KB
003.txt AC 1 ms 256 KB
004.txt AC 1 ms 256 KB
005.txt AC 1 ms 256 KB
006.txt WA 1 ms 256 KB
007.txt AC 1 ms 256 KB
008.txt AC 1 ms 256 KB
009.txt WA 2 ms 256 KB
010.txt WA 2 ms 256 KB
011.txt WA 2 ms 256 KB
012.txt WA 2 ms 256 KB
013.txt WA 2 ms 256 KB
014.txt WA 2 ms 256 KB
015.txt WA 2 ms 256 KB
016.txt WA 2 ms 256 KB
017.txt WA 2 ms 256 KB
018.txt WA 2 ms 256 KB
019.txt WA 2 ms 256 KB
020.txt AC 1 ms 256 KB
021.txt WA 1 ms 256 KB
022.txt WA 1 ms 256 KB
023.txt WA 2 ms 256 KB
024.txt WA 1 ms 256 KB
025.txt WA 1 ms 256 KB
026.txt WA 1 ms 256 KB
027.txt WA 1 ms 256 KB
028.txt WA 1 ms 256 KB
029.txt AC 8 ms 256 KB
030.txt AC 2 ms 256 KB
031.txt WA 3 ms 256 KB
032.txt AC 2 ms 256 KB
033.txt WA 2 ms 256 KB
034.txt AC 2 ms 256 KB
035.txt WA 2 ms 256 KB
036.txt AC 1 ms 256 KB
037.txt WA 2 ms 256 KB
038.txt AC 2 ms 256 KB
039.txt TLE 5255 ms 4096 KB
040.txt WA 856 ms 7424 KB
041.txt WA 179 ms 7424 KB
042.txt WA 289 ms 7424 KB
043.txt WA 193 ms 7424 KB
044.txt WA 100 ms 7424 KB
045.txt TLE 5255 ms 4096 KB
046.txt WA 111 ms 7424 KB
047.txt WA 261 ms 7424 KB
048.txt WA 3243 ms 7424 KB
049.txt WA 808 ms 3328 KB
050.txt WA 105 ms 4224 KB
051.txt WA 193 ms 3712 KB
052.txt WA 144 ms 6784 KB
053.txt TLE 5255 ms 1024 KB
054.txt WA 139 ms 4992 KB
055.txt WA 2 ms 256 KB
056.txt WA 44 ms 1024 KB
057.txt WA 411 ms 3840 KB
058.txt WA 24 ms 1152 KB
059.txt TLE 5255 ms 4096 KB
060.txt AC 98 ms 7424 KB
061.txt TLE 5256 ms 4096 KB
062.txt AC 98 ms 7424 KB
063.txt TLE 5256 ms 4096 KB
064.txt AC 98 ms 7424 KB
065.txt TLE 5256 ms 4096 KB
066.txt AC 98 ms 7424 KB
067.txt TLE 5256 ms 4096 KB
068.txt AC 98 ms 7424 KB
069.txt AC 93 ms 7424 KB
070.txt AC 93 ms 7424 KB
071.txt AC 93 ms 7424 KB
072.txt WA 96 ms 7424 KB
073.txt AC 93 ms 7424 KB
074.txt TLE 5256 ms 4096 KB
075.txt AC 93 ms 7424 KB
076.txt AC 93 ms 7424 KB
077.txt AC 93 ms 7424 KB
078.txt AC 93 ms 7424 KB
079.txt AC 27 ms 2304 KB
080.txt AC 5 ms 512 KB
081.txt AC 9 ms 768 KB
082.txt AC 47 ms 3840 KB
083.txt AC 16 ms 1408 KB
084.txt AC 17 ms 1408 KB
085.txt AC 13 ms 1152 KB
086.txt AC 5 ms 512 KB
087.txt WA 28 ms 2176 KB
088.txt WA 18 ms 1536 KB
089.txt TLE 5255 ms 4096 KB
090.txt AC 91 ms 7424 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB
sample-03.txt AC 1 ms 256 KB