Submission #3433315


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)
            {
                printf("%d %d\n", i, a[i]);
                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 luogu_bot1
Language C++ (GCC 5.4.1)
Score 0
Code Size 1063 Byte
Status WA
Exec Time 5256 ms
Memory 135168 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 × 2
WA × 1
AC × 36
WA × 48
TLE × 9
OLE × 1
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 WA 1 ms 256 KB
004.txt WA 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 3 ms 384 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 WA 1 ms 256 KB
021.txt WA 1 ms 256 KB
022.txt WA 2 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 2 ms 256 KB
027.txt WA 2 ms 256 KB
028.txt WA 1 ms 256 KB
029.txt AC 7 ms 256 KB
030.txt AC 1 ms 256 KB
031.txt WA 6 ms 512 KB
032.txt AC 1 ms 256 KB
033.txt WA 4 ms 384 KB
034.txt AC 2 ms 256 KB
035.txt WA 3 ms 384 KB
036.txt AC 2 ms 256 KB
037.txt WA 3 ms 384 KB
038.txt AC 1 ms 256 KB
039.txt TLE 5255 ms 113024 KB
040.txt WA 1448 ms 57600 KB
041.txt WA 338 ms 21504 KB
042.txt WA 558 ms 30976 KB
043.txt WA 371 ms 23040 KB
044.txt WA 100 ms 7552 KB
045.txt TLE 5256 ms 119424 KB
046.txt WA 134 ms 9472 KB
047.txt WA 504 ms 28800 KB
048.txt WA 4466 ms 112000 KB
049.txt WA 1229 ms 37120 KB
050.txt WA 206 ms 12800 KB
051.txt WA 376 ms 18688 KB
052.txt WA 265 ms 17408 KB
053.txt TLE 5255 ms 1024 KB
054.txt WA 273 ms 16512 KB
055.txt WA 2 ms 256 KB
056.txt WA 103 ms 5248 KB
057.txt WA 715 ms 28416 KB
058.txt WA 53 ms 3328 KB
059.txt TLE 5256 ms 4096 KB
060.txt AC 99 ms 7424 KB
061.txt TLE 5256 ms 107520 KB
062.txt AC 99 ms 7424 KB
063.txt TLE 5256 ms 123520 KB
064.txt AC 98 ms 7424 KB
065.txt TLE 5256 ms 121472 KB
066.txt AC 99 ms 7424 KB
067.txt TLE 5256 ms 100864 KB
068.txt AC 99 ms 7424 KB
069.txt AC 93 ms 7424 KB
070.txt AC 94 ms 7424 KB
071.txt AC 94 ms 7424 KB
072.txt WA 101 ms 7808 KB
073.txt AC 93 ms 7424 KB
074.txt OLE 2133 ms 135168 KB
075.txt AC 94 ms 7424 KB
076.txt AC 94 ms 7424 KB
077.txt AC 94 ms 7424 KB
078.txt AC 93 ms 7424 KB
079.txt AC 28 ms 2304 KB
080.txt AC 5 ms 512 KB
081.txt AC 9 ms 768 KB
082.txt AC 48 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 27 ms 2176 KB
088.txt WA 19 ms 1536 KB
089.txt TLE 5256 ms 4096 KB
090.txt AC 92 ms 7424 KB
sample-01.txt WA 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB
sample-03.txt AC 1 ms 256 KB