Submission #347068

# Submission time Handle Problem Language Result Execution time Memory
347068 2021-01-11T16:10:29 Z cheetose JOI15_building3 (JOI15_building3) C++17
100 / 100
150 ms 14956 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<db, db> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM=MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[]={2,2,-2,-2,1,1,-1,-1},ddy[]={1,-1,1,-1,2,-2,2,-2};

int a[1000000],mx[1000000];
int main() {
	ll ans=0;
	int n;
	scanf("%d",&n);
	n--;
	fup(i,0,n-1,1)scanf("%d",a+i);
	fup(i,0,n-1,1){
		if(a[i]>mx[i]+2)return !printf("0\n");
		if(a[i]==mx[i]+2){
			ans=0;
			fup(j,0,i,1)if(mx[j]==mx[i])ans++;
			mx[i+1]=a[i];
			fup(j,i+1,n-1,1){
				if(a[j]>mx[j]+1)ans=0;
				mx[j+1]=max(mx[j],a[j]);
			}
			return !printf("%lld\n",ans);
		}
		ans+=mx[i]+1;
		mx[i+1]=max(mx[i],a[i]);
	}
	ans+=mx[n]+1;
	printf("%lld\n",ans-n);
}

Compilation message

building3.cpp: In function 'int main()':
building3.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
building3.cpp:49:2: note: in expansion of macro 'fup'
   49 |  fup(i,0,n-1,1)scanf("%d",a+i);
      |  ^~~
building3.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
building3.cpp:50:2: note: in expansion of macro 'fup'
   50 |  fup(i,0,n-1,1){
      |  ^~~
building3.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
building3.cpp:54:4: note: in expansion of macro 'fup'
   54 |    fup(j,0,i,1)if(mx[j]==mx[i])ans++;
      |    ^~~
building3.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
building3.cpp:56:4: note: in expansion of macro 'fup'
   56 |    fup(j,i+1,n-1,1){
      |    ^~~
building3.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
building3.cpp:49:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   49 |  fup(i,0,n-1,1)scanf("%d",a+i);
      |                ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 115 ms 12012 KB Output is correct
22 Correct 117 ms 11520 KB Output is correct
23 Correct 117 ms 12012 KB Output is correct
24 Correct 130 ms 14956 KB Output is correct
25 Correct 134 ms 14956 KB Output is correct
26 Correct 134 ms 14828 KB Output is correct
27 Correct 129 ms 14828 KB Output is correct
28 Correct 133 ms 14828 KB Output is correct
29 Correct 104 ms 10092 KB Output is correct
30 Correct 114 ms 11756 KB Output is correct
31 Correct 120 ms 12396 KB Output is correct
32 Correct 118 ms 12552 KB Output is correct
33 Correct 120 ms 12524 KB Output is correct
34 Correct 119 ms 12396 KB Output is correct
35 Correct 150 ms 14828 KB Output is correct