Submission #1354705


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 2e5 + 100;

int N, Nr[MAX_N];
int main() {
	cin >> N; REP(i, N) scanf("%d", &Nr[i]);
	deque<pi> Q; Q.push_front(pi(N, 0));

	ll Ans = 0, Now = 0;
	for(int i=N-1; i>=0; i--) {
		while(true) {
			int ix, v; tie(ix, v) = Q.front(); 
			if(v > Nr[i]) {
				Q.pop_front();
				Now -= 1ll * v * (Q.front().one - ix);
			}else break;
		}
		Now += 1ll * Nr[i] * (Q.front().one - i);
		Ans += Now;
		Q.push_front(pi(i, Nr[i]));
	}
	printf("%lld\n", Ans);
	return 0;
}

Submission Info

Submission Time
Task B - Minimum Sum
User kajebiii
Language C++14 (GCC 5.4.1)
Score 400
Code Size 888 Byte
Status AC
Exec Time 24 ms
Memory 2688 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:20:41: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  cin >> N; REP(i, N) scanf("%d", &Nr[i]);
                                         ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 13
Set Name Test Cases
Sample example0, example1, example2
All corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2
Case Name Status Exec Time Memory
corner0 AC 22 ms 1024 KB
corner1 AC 23 ms 2688 KB
corner2 AC 1 ms 256 KB
corner3 AC 23 ms 1792 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 24 ms 1024 KB
maxrand1 AC 24 ms 1024 KB
maxrand2 AC 24 ms 1024 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB