Submission #1694317
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll const MOD = 1e9 + 7; int main() { ll n; cin >> n; vector<ll> t(n), a(n), poss(n); for(int i=0;i<n;i++) cin >> t[i]; for(int i=0;i<n;i++) cin >> a[i]; ll ans = 1; if(t[n-1] != a[0]) { ans = 0; } poss[0] = poss[n-1] = 1; for(int i=1;i<n-1;i++) { if(t[i] > t[i-1]) poss[i] = 1; else poss[i] = t[i]; } for(int i=n-2;i>=0;i--) { if(a[i] > a[i+1]) { if(poss[i] == 1 && t[i] != a[i]) ans = 0; if(poss[i] != 1 && t[i] < a[i]) ans = 0; poss[i] = 1; } else { poss[i] = min<ll>(poss[i], a[i]); } } for(int i=0;i<n;i++) { ans *= poss[i]; ans %= MOD; } cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - Two Alpinists |
User | hkr |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 792 Byte |
Status | AC |
Exec Time | 87 ms |
Memory | 2560 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 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 | 2 ms | 384 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 | 87 ms | 2560 KB |
1_009.txt | AC | 75 ms | 2560 KB |
1_010.txt | AC | 77 ms | 2560 KB |
1_011.txt | AC | 80 ms | 2560 KB |
1_012.txt | AC | 79 ms | 2560 KB |
1_013.txt | AC | 80 ms | 2560 KB |
1_014.txt | AC | 83 ms | 2560 KB |
1_015.txt | AC | 81 ms | 2560 KB |
1_016.txt | AC | 78 ms | 2560 KB |
1_017.txt | AC | 75 ms | 2560 KB |
1_018.txt | AC | 73 ms | 2560 KB |
1_019.txt | AC | 65 ms | 2560 KB |
1_020.txt | AC | 61 ms | 2560 KB |