Submission #1918795


Source Code Expand

#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>

#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

struct Edge {
	int from, to, weight;

	bool operator < (const Edge& obj) const {
		return weight < obj.weight;
	}
};

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) { //xの入ってる集合と yの入ってる集合を併合
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) { //xとyが同じ集合に入っているかどうかを判定
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	bool isroot(int x) {
		return data[x] < 0;
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main()
{
	int n;
	cin >> n;
	vector<pii> h(n);
	int bef = -1;
	REP(i, n) {
		int a;
		scanf("%d", &a);
		if (bef < a) {
			h[i] = { 1, a };
		}
		else {
			h[i] = { 0, a };
		}
		bef = a;
	}
	vector<int> s(n);
	REP(i, n) {
		scanf("%d", &s[i]);
	}
	bef = -1;
	bool ok = true;
	for(int i = n-1; 0 <= i; i--) {
		if (bef < s[i]) {
			if (h[i].first == 1 && s[i] != h[i].second) ok = false;
			if (h[i].first == 0 && s[i] > h[i].second) ok = false;
			h[i] = { 1, s[i] };
		}
		else {
			if (h[i].first == 1 && s[i] < h[i].second) ok = false;
			h[i] = { max(h[i].first,0), min(h[i].second, s[i]) };
		}
		bef = s[i];
	}

	if (ok == false) cout << 0 << endl;
	else {
		ll ans = 1;
		REP(i, n) {
			if(h[i].first == 0)
				(ans *= h[i].second)%=MODU;
		}
		cout << ans << endl;
	}

	return 0;
}

Submission Info

Submission Time
Task C - Two Alpinists
User Gear
Language C++14 (Clang 3.8.0)
Score 400
Code Size 3169 Byte
Status AC
Exec Time 27 ms
Memory 1408 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 21
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 AC 1 ms 256 KB
1_007.txt AC 1 ms 256 KB
1_008.txt AC 27 ms 1408 KB
1_009.txt AC 24 ms 1408 KB
1_010.txt AC 25 ms 1408 KB
1_011.txt AC 26 ms 1408 KB
1_012.txt AC 25 ms 1408 KB
1_013.txt AC 26 ms 1408 KB
1_014.txt AC 25 ms 1408 KB
1_015.txt AC 26 ms 1408 KB
1_016.txt AC 25 ms 1408 KB
1_017.txt AC 25 ms 1408 KB
1_018.txt AC 24 ms 1408 KB
1_019.txt AC 23 ms 1408 KB
1_020.txt AC 22 ms 1408 KB