CODE FESTIVAL 2016 qual C

Submission #1348899

Source codeソースコード

//#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];
pair<ll, ll> 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, 1LL);
			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

Task問題 C - 二人のアルピニスト / Two Alpinists
User nameユーザ名 ferin
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 400
Source lengthソースコード長 1722 Byte
File nameファイル名
Exec time実行時間 87 ms
Memory usageメモリ使用量 3328 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_000.txt,0_001.txt,0_002.txt,0_003.txt
All 400 / 400 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
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 AC 1 ms 256 KB
1_007.txt AC 1 ms 256 KB
1_008.txt AC 87 ms 3328 KB
1_009.txt AC 71 ms 3328 KB
1_010.txt AC 76 ms 3328 KB
1_011.txt AC 80 ms 3328 KB
1_012.txt AC 77 ms 3328 KB
1_013.txt AC 79 ms 3328 KB
1_014.txt AC 79 ms 3328 KB
1_015.txt AC 81 ms 3328 KB
1_016.txt AC 77 ms 3328 KB
1_017.txt AC 74 ms 3328 KB
1_018.txt AC 72 ms 3328 KB
1_019.txt AC 63 ms 3328 KB
1_020.txt AC 60 ms 3328 KB