Submission #1817257


Source Code Expand

#include<cstdio>
#include<algorithm>
using namespace std;
int n, w[201000], Loc[201000], G[201000];
struct point{
    int x, num;
    bool operator<(const point &p)const{
        return x!=p.x?x<p.x:num<p.num;
    }
}ord[210000];
void RTE(){
    RTE();
    RTE();
}
int main(){
    int i, j;
    scanf("%d",&n);
    if(n>1000){
        RTE();
    }
    for(i=1;i<=n;i++){
        scanf("%d",&w[i]);
        Loc[i] = i;
        G[i] = i;
        ord[i] = {w[i],i};
    }
    sort(ord+1,ord+n+1);
    long long res = 0;
    for(i=1;i<=n;i++){
        int t = Loc[ord[i].num];
        int M = 0, Mn = 2e9, xx = 0, U = -1;
        for(j=1;j<=t;j++){
            if(Mn >= max(0,M-ord[i].x)+(t-j)){
                Mn = max(0,M-ord[i].x)+(t-j);
                U = max(M, ord[i].x);
                xx = j;
            }
            M = max(M, w[G[j]]);
        }
        w[ord[i].num] = U;
        res += Mn;
        for(j=t;j>xx;j--){
            swap(G[j-1],G[j]);
            swap(Loc[G[j-1]],Loc[G[j]]);
        }
    }
    printf("%lld\n",res);
}

Submission Info

Submission Time
Task B - Increment and Swap
User ainta
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1093 Byte
Status RE
Exec Time 237 ms
Memory 262400 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:17:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
./Main.cpp:22:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&w[i]);
                          ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1500
Status
AC × 2
AC × 3
RE × 63
Set Name Test Cases
Sample example0.txt, example1.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, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt RE 230 ms 262272 KB
001.txt RE 230 ms 262272 KB
002.txt RE 230 ms 262272 KB
003.txt RE 230 ms 262272 KB
004.txt RE 229 ms 262272 KB
005.txt RE 230 ms 262272 KB
006.txt RE 229 ms 262272 KB
007.txt RE 230 ms 262272 KB
008.txt RE 232 ms 262272 KB
009.txt RE 231 ms 262272 KB
010.txt RE 231 ms 262272 KB
011.txt RE 228 ms 262272 KB
012.txt RE 228 ms 262272 KB
013.txt RE 229 ms 262272 KB
014.txt RE 228 ms 262272 KB
015.txt RE 230 ms 262272 KB
016.txt RE 227 ms 262272 KB
017.txt RE 230 ms 262272 KB
018.txt RE 229 ms 262272 KB
019.txt RE 230 ms 262272 KB
020.txt RE 227 ms 262272 KB
021.txt RE 227 ms 262272 KB
022.txt RE 231 ms 262272 KB
023.txt RE 231 ms 262272 KB
024.txt RE 230 ms 262272 KB
025.txt RE 229 ms 262272 KB
026.txt RE 229 ms 262272 KB
027.txt RE 231 ms 262272 KB
028.txt RE 228 ms 262272 KB
029.txt RE 228 ms 262272 KB
030.txt RE 231 ms 262272 KB
031.txt RE 232 ms 262272 KB
032.txt RE 229 ms 262272 KB
033.txt RE 230 ms 262272 KB
034.txt RE 231 ms 262272 KB
035.txt RE 230 ms 262272 KB
036.txt RE 231 ms 262272 KB
037.txt RE 230 ms 262272 KB
038.txt RE 228 ms 262272 KB
039.txt RE 230 ms 262272 KB
040.txt RE 237 ms 262272 KB
041.txt RE 233 ms 262272 KB
042.txt RE 228 ms 262272 KB
043.txt RE 228 ms 262272 KB
044.txt RE 229 ms 262272 KB
045.txt AC 1 ms 128 KB
046.txt RE 228 ms 262272 KB
047.txt RE 230 ms 262272 KB
048.txt RE 229 ms 262272 KB
049.txt RE 232 ms 262272 KB
050.txt RE 227 ms 262400 KB
051.txt RE 227 ms 262272 KB
052.txt RE 229 ms 262272 KB
053.txt RE 229 ms 262272 KB
054.txt RE 230 ms 262272 KB
055.txt RE 227 ms 262272 KB
056.txt RE 232 ms 262272 KB
057.txt RE 229 ms 262272 KB
058.txt RE 229 ms 262272 KB
059.txt RE 232 ms 262272 KB
060.txt RE 227 ms 262272 KB
061.txt RE 230 ms 262272 KB
062.txt RE 230 ms 262272 KB
063.txt RE 230 ms 262272 KB
example0.txt AC 1 ms 128 KB
example1.txt AC 1 ms 128 KB