Submission #1348889
Source Code Expand
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int a[100010], b[100010];
PII c[100010];
signed main(void)
{
int n;
cin >> n;
REP(i, n) cin >> a[i];
REP(i, n) cin >> b[i];
c[0] = PII{a[0], a[0]};
FOR(i, 1, n) {
if(a[i] > a[i-1]) c[i] = {a[i], a[i]};
else if(a[i] == a[i-1]) c[i] = {1, a[i]};
else {cout << 0 << endl; return 0;}
}
//REP(i, n) cout << c[i].first << " " << c[i].second << endl;
//cout << endl;
if(b[n-1] < c[n-1].first && c[n-1].second < b[n-1]) {
cout << 0 << endl;
return 0;
}
c[n-1] = {b[n-1], b[n-1]};
for(int i=n-2; i>=0; --i) {
if(b[i] > b[i+1]) {
if(b[i] < c[i].first || c[i].second < b[i]) {cout << 0 << endl; return 0;}
c[i] = {b[i], b[i]};
} else if(b[i] == b[i+1]) {
if(c[i].first > b[i]) {cout << 0 << endl; return 0;}
c[i].first = max(c[i].first, 1);
c[i].second = min(c[i].second, b[i]);
} else {
cout << 0 << endl;
return 0;
}
}
ll ans = 1;
REP(i, n) {
//cout << c[i].first << " " << c[i].second << endl;
ans = (ans*(c[i].second-c[i].first+1)) % MOD;
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Two Alpinists |
User |
ferin_tech |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1707 Byte |
Status |
WA |
Exec Time |
115 ms |
Memory |
1792 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 400 |
Status |
|
|
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 |
WA |
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 |
115 ms |
1792 KB |
1_009.txt |
AC |
95 ms |
1792 KB |
1_010.txt |
AC |
99 ms |
1792 KB |
1_011.txt |
AC |
107 ms |
1792 KB |
1_012.txt |
AC |
101 ms |
1792 KB |
1_013.txt |
AC |
106 ms |
1792 KB |
1_014.txt |
AC |
104 ms |
1792 KB |
1_015.txt |
AC |
108 ms |
1792 KB |
1_016.txt |
AC |
102 ms |
1792 KB |
1_017.txt |
AC |
99 ms |
1792 KB |
1_018.txt |
AC |
94 ms |
1792 KB |
1_019.txt |
AC |
82 ms |
1792 KB |
1_020.txt |
AC |
76 ms |
1792 KB |