Submission #1707188
Source Code Expand
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x) cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif
//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
//ここから編集する
class Combination {
#define MOD 1000000007
public:
vector<ll> fact;
Combination(int max_n) {
//1 ~ n!までの階乗modを求める
int n = max_n;
vector<ll> fact(n + 1);
fact[0] = 1;
for (int i = 1; i <= n; i++) {
fact[i] = (fact[i - 1] * i) % MOD;
}
this->fact = fact;
}
template<typename T>
//templateをつかってみtか
ll pow(T x, int y) {
if (y == 0) return 1;
if (y == 1) return x;
if (y == 2) return (x * x) % MOD;
// if (y % 2 == 1) return pow(x, y / 2) * pow(x, y / 2) % MOD;
if (y % 2 == 1) return pow(pow(x, y / 2), 2) * x % MOD;
// return pow(x, y / 2) * pow(x, y / 2) % MOD;
return pow(pow(x, y / 2), 2) % MOD;
}
ll nCk(int n, int k) {
// return (fact[n] * pow(fact[n-k],MOD-2) * pow(fact[k],MOD-2)) % MOD;
return (((fact[n] * pow(fact[n - k], MOD - 2)) % MOD) * pow(fact[k], MOD - 2)) % MOD;
}
};
int main() {
int N;
cin >> N;
vector<int> T(N + 1,0);
vector<int> A(N + 1,0);
vector<int> h(N + 2, 0);
REP(i, 1, N + 1) {
cin >> T[i];
}
REP(i, 1, N + 1) {
cin >> A[i];
}
h[1] = T[1];
REP(i,1,N+1){
if(T[i] > T[i-1]){
h[i] = T[i];
}else{
h[i] = -T[i];
}
}
// REP(i,2,N+1){
// if(A[i] < A[i-1]){
// if(h[i] == 0){
// h[i] = A[i];
// }else{
// if(h[i] != A[i]){
// cout << 0 << endl;
// return 0;
// }
// }
// }
// }
for(int i = N+1; i > 1; i--){
if(A[i - 1] > A[i]){
if(h[i-1] <= 0){
h[i-1] = A[i-1];
}else{
if(h[i-1] != A[i-1]){
cout << 0 << endl;
return 0;
}
}
}else{
if(h[i-1] == 0) h[i-1] = -A[i-1];
else if(h[i-1] < 0) h[i-1] = -min(-h[i-1],A[i-1]);
}
}
ll ans = 1;
REP(i,1,N){
if(h[i] < 0){
ans = ans * (-h[i]) % MOD;
}
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Two Alpinists |
User |
homesentinel |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
3696 Byte |
Status |
WA |
Exec Time |
87 ms |
Memory |
1408 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 |
AC |
1 ms |
256 KB |
1_005.txt |
AC |
1 ms |
256 KB |
1_006.txt |
WA |
1 ms |
256 KB |
1_007.txt |
AC |
1 ms |
256 KB |
1_008.txt |
AC |
87 ms |
1408 KB |
1_009.txt |
AC |
71 ms |
1408 KB |
1_010.txt |
AC |
76 ms |
1408 KB |
1_011.txt |
AC |
81 ms |
1408 KB |
1_012.txt |
AC |
78 ms |
1408 KB |
1_013.txt |
AC |
80 ms |
1408 KB |
1_014.txt |
AC |
80 ms |
1408 KB |
1_015.txt |
AC |
81 ms |
1408 KB |
1_016.txt |
AC |
78 ms |
1408 KB |
1_017.txt |
AC |
75 ms |
1408 KB |
1_018.txt |
WA |
73 ms |
1408 KB |
1_019.txt |
AC |
64 ms |
1408 KB |
1_020.txt |
WA |
61 ms |
1408 KB |