Submission #2535474
Source Code Expand
#include <cstdio> #include <iostream> #include <algorithm> #include <vector> #include <set> #include <list> #include <map> #include <string> #include <cstring> #include <stack> #include <queue> #include <cmath> #include <ctime> #include <bitset> #include <utility> #include <complex> #include <assert.h> #include <limits.h> #include <iomanip> #include <unordered_map> //#include <bits/stdc++.h> using namespace std; #define rank rankk #define mp make_pair #define pb push_back #define xo(a,b) ((b)&1?(a):0) #define tm tmp //#define LL ll typedef unsigned long long ull; typedef pair<int,int> pii; typedef long long ll; typedef pair<ll,int> pli; typedef pair<int,ll>pil; typedef pair<ll,ll> pll; //const double INF=1e20; const int INF=0x3f3f3f3f; //const int INF= 0x7fffffff; //const ll INF=0x3f3f3f3f3f3f3f3fll; const ll INFF=0x3f3f3f3f3f3f3f3fll; //const ll INFF=1e14+5; const int MAX=2e5+5; //const ll MAXN=2e8; //const int MAX_N=MAX; const int MOD=1e9+7; //const ull MOD=1e7+7; //const ll MOD=998244353; //const long double pi=acos(-1.0); //const double eps=0.00000001; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} template<typename T>inline T abs(T a) {return a>0?a:-a;} //#define double long double template<class T> inline void read(T& num) { bool start=false,neg=false; char c; num=0; while((c=getchar())!=EOF) { if(c=='-') start=neg=true; else if(c>='0' && c<='9') { start=true; num=num*10+c-'0'; } else if(start) break; } if(neg) num=-num; } inline ll powMM(ll a,ll b,ll M){ ll ret=1; a%=M; // b%=M; while (b){ if (b&1) ret=ret*a%M; b>>=1; a=a*a%M; } return ret; } //const long double eps=-1.0; //clock_t t1 = clock(); //fprintf(stderr, "%ld ms\n", clock() - t1); void open() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); } int n; int a[MAX]; ll an; map<int,int>re; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); if(a[1])return 0*printf("-1\n"); for(int i=2;i<=n;i++) if(a[i]>a[i-1]+1)return 0*printf("-1\n"); int cnt=-1; for(int i=2;i<=n;i++) { if(re[a[i]+cnt]) { an+=i-re[a[i]+cnt]; } else an+=a[i]; re[a[i]+cnt]=i; --cnt; } printf("%lld\n",an); } /* */
Submission Info
Submission Time | |
---|---|
Task | C - Sequence Growing Easy |
User | for0nething |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 2469 Byte |
Status | AC |
Exec Time | 130 ms |
Memory | 10368 KiB |
Compile Error
./Main.cpp: In function ‘void open()’: ./Main.cpp:83:35: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result] freopen("input.txt","r",stdin); ^ ./Main.cpp:84:37: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result] freopen("output.txt","w",stdout); ^ ./Main.cpp: In function ‘int main()’: ./Main.cpp:93:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:95:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&a[i]); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, s1.txt, s2.txt, s3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 24 ms | 1024 KiB |
02.txt | AC | 24 ms | 1024 KiB |
03.txt | AC | 21 ms | 1024 KiB |
04.txt | AC | 21 ms | 1024 KiB |
05.txt | AC | 20 ms | 1024 KiB |
06.txt | AC | 20 ms | 1024 KiB |
07.txt | AC | 106 ms | 5760 KiB |
08.txt | AC | 104 ms | 5760 KiB |
09.txt | AC | 106 ms | 5632 KiB |
10.txt | AC | 108 ms | 5760 KiB |
11.txt | AC | 19 ms | 1024 KiB |
12.txt | AC | 19 ms | 1024 KiB |
13.txt | AC | 19 ms | 1024 KiB |
14.txt | AC | 19 ms | 1024 KiB |
15.txt | AC | 90 ms | 5760 KiB |
16.txt | AC | 90 ms | 5760 KiB |
17.txt | AC | 90 ms | 5760 KiB |
18.txt | AC | 91 ms | 5760 KiB |
19.txt | AC | 23 ms | 1024 KiB |
20.txt | AC | 22 ms | 1024 KiB |
21.txt | AC | 130 ms | 5248 KiB |
22.txt | AC | 119 ms | 6912 KiB |
23.txt | AC | 123 ms | 5248 KiB |
24.txt | AC | 124 ms | 8320 KiB |
25.txt | AC | 24 ms | 1024 KiB |
26.txt | AC | 23 ms | 1024 KiB |
27.txt | AC | 23 ms | 1024 KiB |
28.txt | AC | 24 ms | 1024 KiB |
29.txt | AC | 23 ms | 1024 KiB |
30.txt | AC | 23 ms | 1024 KiB |
31.txt | AC | 19 ms | 1024 KiB |
32.txt | AC | 19 ms | 1024 KiB |
33.txt | AC | 116 ms | 10368 KiB |
34.txt | AC | 127 ms | 5760 KiB |
35.txt | AC | 61 ms | 5760 KiB |
36.txt | AC | 61 ms | 5760 KiB |
37.txt | AC | 110 ms | 9728 KiB |
38.txt | AC | 111 ms | 9472 KiB |
39.txt | AC | 34 ms | 3200 KiB |
40.txt | AC | 23 ms | 1024 KiB |
41.txt | AC | 1 ms | 256 KiB |
42.txt | AC | 1 ms | 256 KiB |
43.txt | AC | 1 ms | 256 KiB |
44.txt | AC | 1 ms | 256 KiB |
45.txt | AC | 1 ms | 256 KiB |
46.txt | AC | 1 ms | 256 KiB |
s1.txt | AC | 1 ms | 256 KiB |
s2.txt | AC | 1 ms | 256 KiB |
s3.txt | AC | 1 ms | 256 KiB |