Submission #2278000


Source Code Expand

# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<long long>::max();
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, s, t, q, sum[100001], last, cnt, ans,a[101000];
struct Edge { LL to, cost; };
string str;
bool f;
vector<Edge>vec[1000];
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
		a[n] = 0;
	LL mx = 0;
	Tll carp = Tll{0,0,0};
	do {
		stack<Pll>st;
		mx = 0;
		f = 0;
		LL ss = 0;
		rep(i, n+1) {
			ss += sum[i];
			if (sum[i + 1] == 0) {
				while (!st.empty()) {
					Pll now = st.top();
					if (now.fir <= a[i]) break;
					st.pop();
					if (mx < (i - now.sec)*(now.fir-ss)) {
						mx = (i - now.sec)*(now.fir-ss);
						carp = Tll{ now.sec, i, now.fir };
					}
				}
				if (st.empty()&&mx!=0) {
					f = 1;
					ans++;
					sum[carp.fir] += carp.third;
					sum[carp.sec + 1] -= carp.third;
					mx = 0;
				}
				if ((st.empty()?1:st.top().fir < a[i]&&a[i]>0))
					st.push(Pll(a[i], i));
			}
			else {
				while (!st.empty()) {
					Pll now = st.top();
					st.pop();
					if (mx < (i - now.sec)*(now.fir-ss)) {
						mx = (i - now.sec)*(now.fir-ss);
						carp = Tll{ now.sec, i, now.fir };
					}
				}
				if (mx != 0) {
					f = 1;
					ans++;
					sum[carp.fir] += carp.third-ss;
					sum[carp.sec + 1] -= carp.third-ss;
					mx = 0;
				}
			}
		}
	} while (f == 1);
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task D - カーペット
User akusyounin
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2673 Byte
Status RE
Exec Time 182 ms
Memory 1920 KB

Judge Result

Set Name All
Score / Max Score 0 / 250
Status
AC × 14
WA × 42
RE × 50
Set Name Test Cases
All 00_max_04.txt, 00_max_05.txt, 00_max_06.txt, 00_max_07.txt, 00_max_08.txt, 00_max_09.txt, 00_max_10.txt, 00_min_00.txt, 00_min_01.txt, 00_min_02.txt, 00_min_03.txt, 00_rand_18.txt, 00_rand_19.txt, 00_rand_20.txt, 00_rand_21.txt, 00_rand_22.txt, 00_rand_23.txt, 00_rand_30.txt, 00_rand_31.txt, 00_rand_32.txt, 00_rand_33.txt, 00_rand_34.txt, 00_rand_35.txt, 00_rand_36.txt, 00_rand_37.txt, 00_sample_00.txt, 00_sample_01.txt, 10_max_11.txt, 10_max_12.txt, 10_max_13.txt, 10_max_14.txt, 10_max_15.txt, 10_max_16.txt, 10_max_17.txt, 10_rand_24.txt, 10_rand_25.txt, 10_rand_26.txt, 10_rand_27.txt, 10_rand_28.txt, 10_rand_29.txt, 10_rand_38.txt, 10_rand_39.txt, 10_rand_40.txt, 10_rand_41.txt, 10_rand_42.txt, 10_rand_43.txt, 10_rand_44.txt, 10_rand_45.txt, 10_random_00.txt, 10_random_01.txt, 10_random_02.txt, 10_random_03.txt, 10_random_04.txt, 10_random_05.txt, 10_random_06.txt, 10_random_07.txt, 10_random_08.txt, 10_random_09.txt, 10_random_10.txt, 10_random_11.txt, 10_random_12.txt, 10_random_13.txt, 10_random_14.txt, 10_random_15.txt, 10_random_16.txt, 10_random_17.txt, 10_random_18.txt, 10_random_19.txt, 10_random_20.txt, 10_random_21.txt, 10_random_22.txt, 10_random_23.txt, 10_random_24.txt, 10_random_25.txt, 10_random_26.txt, 10_random_27.txt, 10_random_28.txt, 10_random_29.txt, 10_random_30.txt, 10_random_31.txt, 10_random_32.txt, 10_random_33.txt, 10_random_34.txt, 10_random_35.txt, 10_random_36.txt, 10_random_37.txt, 10_random_38.txt, 10_random_39.txt, 10_random_40.txt, 10_random_41.txt, 10_random_42.txt, 10_random_43.txt, 10_random_44.txt, 10_random_45.txt, 10_random_46.txt, 10_random_47.txt, 10_random_48.txt, 10_random_49.txt, 10_random_50.txt, 10_random_51.txt, 10_random_52.txt, 10_random_53.txt, 10_random_54.txt, 10_random_55.txt, 10_random_56.txt, 10_random_57.txt
Case Name Status Exec Time Memory
00_max_04.txt WA 2 ms 256 KB
00_max_05.txt WA 1 ms 256 KB
00_max_06.txt AC 2 ms 256 KB
00_max_07.txt WA 1 ms 256 KB
00_max_08.txt AC 1 ms 256 KB
00_max_09.txt AC 2 ms 256 KB
00_max_10.txt WA 1 ms 256 KB
00_min_00.txt AC 1 ms 256 KB
00_min_01.txt AC 1 ms 256 KB
00_min_02.txt AC 1 ms 256 KB
00_min_03.txt WA 1 ms 256 KB
00_rand_18.txt WA 1 ms 256 KB
00_rand_19.txt WA 1 ms 256 KB
00_rand_20.txt WA 1 ms 256 KB
00_rand_21.txt WA 2 ms 256 KB
00_rand_22.txt WA 2 ms 256 KB
00_rand_23.txt WA 2 ms 256 KB
00_rand_30.txt WA 1 ms 256 KB
00_rand_31.txt WA 1 ms 256 KB
00_rand_32.txt WA 1 ms 256 KB
00_rand_33.txt WA 2 ms 256 KB
00_rand_34.txt WA 2 ms 256 KB
00_rand_35.txt WA 2 ms 256 KB
00_rand_36.txt WA 2 ms 256 KB
00_rand_37.txt WA 2 ms 256 KB
00_sample_00.txt AC 1 ms 256 KB
00_sample_01.txt AC 1 ms 256 KB
10_max_11.txt RE 177 ms 1792 KB
10_max_12.txt RE 156 ms 1792 KB
10_max_13.txt RE 174 ms 1792 KB
10_max_14.txt RE 155 ms 1920 KB
10_max_15.txt RE 126 ms 1792 KB
10_max_16.txt RE 175 ms 1792 KB
10_max_17.txt RE 151 ms 1792 KB
10_rand_24.txt RE 153 ms 1408 KB
10_rand_25.txt RE 158 ms 1280 KB
10_rand_26.txt RE 154 ms 1408 KB
10_rand_27.txt RE 173 ms 1792 KB
10_rand_28.txt RE 175 ms 1792 KB
10_rand_29.txt RE 177 ms 1792 KB
10_rand_38.txt WA 6 ms 384 KB
10_rand_39.txt WA 34 ms 896 KB
10_rand_40.txt WA 34 ms 896 KB
10_rand_41.txt RE 175 ms 1792 KB
10_rand_42.txt RE 182 ms 1792 KB
10_rand_43.txt RE 175 ms 1792 KB
10_rand_44.txt RE 175 ms 1792 KB
10_rand_45.txt RE 175 ms 1792 KB
10_random_00.txt AC 1 ms 256 KB
10_random_01.txt AC 1 ms 256 KB
10_random_02.txt AC 1 ms 256 KB
10_random_03.txt WA 1 ms 256 KB
10_random_04.txt WA 2 ms 256 KB
10_random_05.txt WA 1 ms 256 KB
10_random_06.txt AC 2 ms 256 KB
10_random_07.txt WA 1 ms 256 KB
10_random_08.txt AC 1 ms 256 KB
10_random_09.txt AC 2 ms 256 KB
10_random_10.txt WA 1 ms 256 KB
10_random_11.txt RE 178 ms 1792 KB
10_random_12.txt RE 155 ms 1792 KB
10_random_13.txt RE 174 ms 1792 KB
10_random_14.txt RE 154 ms 1792 KB
10_random_15.txt RE 126 ms 1792 KB
10_random_16.txt RE 177 ms 1792 KB
10_random_17.txt RE 151 ms 1792 KB
10_random_18.txt WA 1 ms 256 KB
10_random_19.txt WA 1 ms 256 KB
10_random_20.txt WA 2 ms 256 KB
10_random_21.txt WA 2 ms 256 KB
10_random_22.txt WA 2 ms 256 KB
10_random_23.txt WA 2 ms 256 KB
10_random_24.txt RE 154 ms 1408 KB
10_random_25.txt RE 151 ms 1280 KB
10_random_26.txt RE 156 ms 1408 KB
10_random_27.txt RE 178 ms 1792 KB
10_random_28.txt RE 175 ms 1792 KB
10_random_29.txt RE 177 ms 1792 KB
10_random_30.txt WA 2 ms 256 KB
10_random_31.txt WA 1 ms 256 KB
10_random_32.txt WA 1 ms 256 KB
10_random_33.txt WA 2 ms 256 KB
10_random_34.txt WA 2 ms 256 KB
10_random_35.txt WA 2 ms 256 KB
10_random_36.txt WA 13 ms 512 KB
10_random_37.txt RE 144 ms 1152 KB
10_random_38.txt WA 21 ms 640 KB
10_random_39.txt WA 14 ms 512 KB
10_random_40.txt RE 145 ms 1280 KB
10_random_41.txt RE 175 ms 1792 KB
10_random_42.txt RE 175 ms 1792 KB
10_random_43.txt RE 174 ms 1792 KB
10_random_44.txt RE 174 ms 1792 KB
10_random_45.txt RE 175 ms 1792 KB
10_random_46.txt RE 175 ms 1792 KB
10_random_47.txt RE 175 ms 1792 KB
10_random_48.txt RE 175 ms 1792 KB
10_random_49.txt RE 175 ms 1792 KB
10_random_50.txt RE 176 ms 1792 KB
10_random_51.txt RE 175 ms 1792 KB
10_random_52.txt RE 174 ms 1792 KB
10_random_53.txt RE 178 ms 1792 KB
10_random_54.txt RE 172 ms 1792 KB
10_random_55.txt RE 174 ms 1792 KB
10_random_56.txt RE 175 ms 1792 KB
10_random_57.txt RE 175 ms 1792 KB