Submission #1691606


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ll n; cin >> n;
	ll t[n], a[n];
	for(int i = 0; i < n; ++i) cin >> t[i];
	for(int i = 0; i < n; ++i) cin >> a[i];
	vector<pair<ll, bool> > po(n, pair<ll, bool>(1145148931919810, 0));
	ll maxv = t[0];
	po[0] = pair<ll, bool>(t[0], 1);
	for(int i = 1; i < n; ++i){
		if(t[i] > maxv){
			maxv = t[i];
			po[i] = pair<ll, bool>(t[i], 1);
		}else{
			po[i] = pair<ll, bool>(maxv, 0);
		}
	}
	if(po[n - 1].first != a[n - 1] && po[n - 1].second){
		cout << 0 << endl;
		return 0;
	}else{
		po[n - 1] = pair<ll, bool>(a[n - 1], 1);
	}
	maxv = a[n - 1];
	for(int i = n - 2; i >= 0; --i){
		if(a[i] > maxv){
			if(po[i].first != a[i] && po[i].second){
				cout << 0 << endl;
				return 0;
			}
			po[i] = pair<ll, bool>(a[i], 1);
			maxv = a[i];
		}else{
			if(po[i].second && po[i].first > maxv){
				cout << 0 << endl;
				return 0;
			}else{
				if(!po[i].second) po[i].first = min<ll>(po[i].first, a[i]);
			}
		}
	}
	ll ans = 1;
	ll mod = 1e9 + 7;
	for(int i = 0; i < n; ++i){
		if(!po[i].second){
			ans *= po[i].first;
			ans %= mod;
		}
	}
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task C - Two Alpinists
User kcvlex
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1207 Byte
Status AC
Exec Time 99 ms
Memory 3328 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 21
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt
Case Name Status Exec Time Memory
0_000.txt AC 1 ms 256 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 1 ms 256 KB
0_003.txt AC 1 ms 256 KB
1_004.txt AC 1 ms 256 KB
1_005.txt AC 1 ms 256 KB
1_006.txt AC 1 ms 256 KB
1_007.txt AC 1 ms 256 KB
1_008.txt AC 99 ms 3328 KB
1_009.txt AC 73 ms 3328 KB
1_010.txt AC 80 ms 3328 KB
1_011.txt AC 87 ms 3328 KB
1_012.txt AC 82 ms 3328 KB
1_013.txt AC 84 ms 3328 KB
1_014.txt AC 83 ms 3328 KB
1_015.txt AC 86 ms 3328 KB
1_016.txt AC 82 ms 3328 KB
1_017.txt AC 79 ms 3328 KB
1_018.txt AC 77 ms 3328 KB
1_019.txt AC 67 ms 3328 KB
1_020.txt AC 61 ms 3328 KB