Submission #1164082


Source Code Expand

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;
typedef vector<pii> vp;

#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-8)
#define PI (acos(-1))
const ll MOD = 1000000007ll;

ll mod_pow(ll x, ll n, ll mod) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	
	return res;
}

int n;
int a[112345], b[112345];
int data[2][112345];
int c[112345];

int main() {	
	cin >> n;
	REP(i, n) scanf("%d", a + i);
	REP(i, n) scanf("%d", b + i);
	
	fill(data[0], data[2], -1);
	data[0][0] = a[0];
	FOR(i, 1, n) if (a[i] != a[i - 1]) data[0][i] = a[i];
	
	data[1][n - 1] = b[n - 1];
	for (int i = n - 2; i >= 0; i--) if (b[i] != b[i + 1]) data[1][i] = b[i];
	
	fill(c, c + n, -1);
	
	bool ng = false;
	REP(i, n) {
		if (~data[0][i] && ~data[1][i]) {
			if (data[0][i] != data[1][i]) ng = true;
			else c[i] = data[0][i];
		}
		else {
			if (~data[0][i]) c[i] = data[0][i];
			if (~data[1][i]) c[i] = data[1][i];
		}
	}
	
	if (ng) puts("0");
	else {
		ll ans = 1;
		
		int pos = 0;
		while (pos < n) {
			if (c[pos] != -1) {
				pos++;
				continue;
			}
			
			int cnt = 0, l = pos - 1;
			while (c[pos] == -1) pos++, cnt++;
			int r = pos;
			
			ans = ans * mod_pow(min(a[l], b[r]), cnt, MOD) % MOD;
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

Submission Info

Submission Time
Task C - Two Alpinists
User tkmst201
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2068 Byte
Status WA
Exec Time 26 ms
Memory 2304 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:53:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  REP(i, n) scanf("%d", a + i);
                              ^
./Main.cpp:54:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  REP(i, n) scanf("%d", b + i);
                              ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 4
AC × 18
WA × 3
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 1152 KB
0_001.txt AC 2 ms 1152 KB
0_002.txt AC 2 ms 1152 KB
0_003.txt AC 2 ms 1152 KB
1_004.txt AC 2 ms 1152 KB
1_005.txt AC 2 ms 1152 KB
1_006.txt WA 2 ms 1152 KB
1_007.txt AC 2 ms 1152 KB
1_008.txt AC 25 ms 2304 KB
1_009.txt AC 23 ms 2304 KB
1_010.txt AC 24 ms 2304 KB
1_011.txt AC 26 ms 2304 KB
1_012.txt AC 25 ms 2304 KB
1_013.txt AC 25 ms 2304 KB
1_014.txt AC 24 ms 2304 KB
1_015.txt AC 24 ms 2304 KB
1_016.txt AC 24 ms 2304 KB
1_017.txt AC 23 ms 2304 KB
1_018.txt WA 23 ms 2304 KB
1_019.txt AC 22 ms 2304 KB
1_020.txt WA 21 ms 2304 KB