Submission #5948213
Source Code Expand
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007
template<typename T>
int vector_finder(std::vector<T> vec, T number) {
auto itr = std::find(vec.begin(), vec.end(), number);
size_t index = std::distance( vec.begin(), itr );
if (index != vec.size()) { // 発見できたとき
return 1;
}
else { // 発見できなかったとき
return 0;
}
}
template<typename T>
T gcd(T a,T b){
if(b>0){
return gcd(b, a % b);
}else{
return a;
}
}
template<typename T>
T lcm(T a,T b){
T g = gcd(a, b);
return a * b / g;
}
void clear( std::queue<pair<int,int> > &q )
{
std::queue<pair<int,int> > empty;
std::swap( q, empty );
}
bool IsPrime(int num)
{
if (num < 2) return false;
else if (num == 2) return true;
else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2)
{
if (num % i == 0)
{
// 素数ではない
return false;
}
}
// 素数である
return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
std::vector<T> ret;
for(T i=1 ; i*i<=n ; ++i)
{
if(n%i == 0)
{
ret.push_back(i);
if(i!=1 && i*i!=n)
{
ret.push_back(n/i);
}
}
}
return ret;
}
class DisjointSet{
public:
vector<int> rank, p;
DisjointSet(){
}
DisjointSet(int size){
rank.resize(size, 0);
p.resize(size, 0);
for (int i = 0; i < size;i++){
makeSet(i);
}
}
void makeSet(int x){
p[x] = x;
rank[x] = 0;
}
bool same(int x,int y){
return findSet(x) == findSet(y);
}
void unite(int x,int y){
link(findSet(x), findSet(y));
}
void link(int x,int y){
if(rank[x]>rank[y]){
p[y] = x;
}else{
p[x] = y;
if(rank[x]==rank[y]){
rank[y]++;
}
}
}
int findSet(int x){
if(x!=p[x]){
p[x] = findSet(p[x]);
}
return p[x];
}
};
int main()
{
int N;
cin >> N;
ll T[N];
ll A[N];
REP(i,0,N){
cin >> T[i];
}
REP(i,0,N){
cin >> A[i];
}
int start = -1;
int end = -1;
bool flag = false;
REP(i, 0, N)
{
if(T[i]==A[i]&&!flag){
start = i;
flag = true;
}
if(T[i]!=A[i]&&flag&&end==-1){
end = i - 1;
}
}
if (start == -1 || T[N - 1] != A[0])
{
cout << 0 << endl;
return 0;
}
ll ans = 1;
if (end == -1)
{
REP(i,0,start){
if(T[i]==T[i+1]){
ans *= T[i] % MOD;
ans %= MOD;
}
}
if(start<N-1){
REP(i,start+1,N-1){
ans *= T[start] % MOD;
ans %= MOD;
}
}
}
else{
REP(i,0,start){
if(T[i]==T[i+1]){
ans *= T[i] % MOD;
ans %= MOD;
}
}
for (int i = N - 1; i >end;i--){
if(A[i]==A[i-1]){
ans *= A[i] % MOD;
ans %= MOD;
}
}
if(end>start+1){
int num = end - start - 1;
REP(i,0,num){
ans *= T[start] % MOD;
ans %= MOD;
}
}
}
cout << ans << endl;
}
Submission Info
Submission Time |
|
Task |
C - Two Alpinists |
User |
nazonazokun |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
4128 Byte |
Status |
WA |
Exec Time |
88 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 |
AC |
1 ms |
256 KB |
1_005.txt |
WA |
1 ms |
256 KB |
1_006.txt |
AC |
1 ms |
256 KB |
1_007.txt |
AC |
1 ms |
256 KB |
1_008.txt |
AC |
88 ms |
1792 KB |
1_009.txt |
AC |
70 ms |
1792 KB |
1_010.txt |
AC |
75 ms |
1792 KB |
1_011.txt |
AC |
79 ms |
1792 KB |
1_012.txt |
AC |
76 ms |
1792 KB |
1_013.txt |
AC |
79 ms |
1792 KB |
1_014.txt |
AC |
79 ms |
1792 KB |
1_015.txt |
AC |
80 ms |
1792 KB |
1_016.txt |
AC |
77 ms |
1792 KB |
1_017.txt |
AC |
74 ms |
1792 KB |
1_018.txt |
AC |
72 ms |
1792 KB |
1_019.txt |
AC |
63 ms |
1792 KB |
1_020.txt |
AC |
59 ms |
1792 KB |