Submission #1865015


Source Code Expand

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const int N=10005;
int a[N];
int main()
{
	int n;scanf("%d",&n);int x;scanf("%d",&x);a[1]=x;int ans=0;
	rep(i,2,n)
	{
		scanf("%d",&x);int cnt=i;
		rep(j,1,i-1)if(a[j]>x){cnt=j;break;}
		int res1=i-cnt,res2=max(0,a[i-1]-x);
		if(res1>res2)
		{
			a[i]=max(a[i-1],x);
			ans+=max(0,a[i-1]-x);	
		}
		else
		{
			per(j,i-1,cnt)a[j+1]=a[j];
			a[cnt]=x;
			ans+=res1;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Submission Info

Submission Time
Task B - Increment and Swap
User eden_ak_noi2018
Language C++14 (GCC 5.4.1)
Score 0
Code Size 618 Byte
Status RE
Exec Time 145 ms
Memory 128 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:12:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  int n;scanf("%d",&n);int x;scanf("%d",&x);a[1]=x;int ans=0;
                      ^
./Main.cpp:12:43: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  int n;scanf("%d",&n);int x;scanf("%d",&x);a[1]=x;int ans=0;
                                           ^
./Main.cpp:15:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);int cnt=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 137 ms 128 KB
001.txt RE 137 ms 128 KB
002.txt RE 137 ms 128 KB
003.txt RE 138 ms 128 KB
004.txt RE 137 ms 128 KB
005.txt RE 137 ms 128 KB
006.txt RE 137 ms 128 KB
007.txt RE 138 ms 128 KB
008.txt RE 138 ms 128 KB
009.txt RE 137 ms 128 KB
010.txt RE 140 ms 128 KB
011.txt RE 137 ms 128 KB
012.txt RE 138 ms 128 KB
013.txt RE 138 ms 128 KB
014.txt RE 138 ms 128 KB
015.txt RE 137 ms 128 KB
016.txt RE 137 ms 128 KB
017.txt RE 138 ms 128 KB
018.txt RE 137 ms 128 KB
019.txt RE 138 ms 128 KB
020.txt RE 138 ms 128 KB
021.txt RE 131 ms 128 KB
022.txt RE 140 ms 128 KB
023.txt RE 137 ms 128 KB
024.txt RE 140 ms 128 KB
025.txt RE 137 ms 128 KB
026.txt RE 138 ms 128 KB
027.txt RE 138 ms 128 KB
028.txt RE 139 ms 128 KB
029.txt RE 139 ms 128 KB
030.txt RE 138 ms 128 KB
031.txt RE 138 ms 128 KB
032.txt RE 138 ms 128 KB
033.txt RE 138 ms 128 KB
034.txt RE 138 ms 128 KB
035.txt RE 139 ms 128 KB
036.txt RE 138 ms 128 KB
037.txt RE 139 ms 128 KB
038.txt RE 138 ms 128 KB
039.txt RE 139 ms 128 KB
040.txt RE 138 ms 128 KB
041.txt RE 138 ms 128 KB
042.txt RE 129 ms 128 KB
043.txt RE 145 ms 128 KB
044.txt RE 143 ms 128 KB
045.txt AC 0 ms 128 KB
046.txt RE 99 ms 128 KB
047.txt RE 138 ms 128 KB
048.txt RE 133 ms 128 KB
049.txt RE 131 ms 128 KB
050.txt RE 127 ms 128 KB
051.txt RE 128 ms 128 KB
052.txt RE 129 ms 128 KB
053.txt RE 138 ms 128 KB
054.txt RE 137 ms 128 KB
055.txt RE 129 ms 128 KB
056.txt RE 112 ms 128 KB
057.txt RE 101 ms 128 KB
058.txt RE 96 ms 128 KB
059.txt RE 100 ms 128 KB
060.txt RE 137 ms 128 KB
061.txt RE 139 ms 128 KB
062.txt RE 130 ms 128 KB
063.txt RE 95 ms 128 KB
example0.txt AC 0 ms 128 KB
example1.txt AC 1 ms 128 KB