CODE FESTIVAL 2016 qual C

Submission #1754670

Source codeソースコード

#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

#define INF 1000000007;

bool lock[100010];
ll dp[100010];
ll a[100010],b[100010];

int main()
{
	int n;cin >> n;
	
	REP(i,n)dp[i] = INF;
	REP(i,n)cin >> a[i];
	REP(i,n)cin >> b[i];
	
	ll now = 0;
	REP(i,n)
	{
		if(a[i] > now)
		{
			lock[i] = true;
			now = a[i];
		}
		dp[i] = min(dp[i],now);
	}
	
	now = 0;
	REP(i,n)
	{
		if(lock[n-i-1] && b[n-i-1] < dp[n-i-1])
		{
			cout << 0 << endl;
			return 0;
		}
		
		if(b[n-i-1] > now)
		{
			if(lock[n-i-1] && b[n-i-1] != dp[n-i-1])
			{
				cout << 0 << endl;
				return 0;
				
			}
			lock[n-i-1] = true;
		}
		now = b[n-i-1];
			
		dp[n-i-1] = min(dp[n-i-1],now);
	}
	
	ll ans = 1;
	
	REP(i,n)
	{
		if(!lock[i])
		{
			ans = (ans*dp[i]) % INF;
		}
	}
	
	//SHOW1d(dp,n);
	//SHOW1d(lock,n);
	
	cout << ans << endl;
	
	return 0;
}

Submission

Task問題 C - 二人のアルピニスト / Two Alpinists
User nameユーザ名 seica
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 400
Source lengthソースコード長 1826 Byte
File nameファイル名
Exec time実行時間 86 ms
Memory usageメモリ使用量 2688 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 86 ms 2560 KB
1_009.txt AC 70 ms 2688 KB
1_010.txt AC 75 ms 2688 KB
1_011.txt AC 80 ms 2688 KB
1_012.txt AC 77 ms 2688 KB
1_013.txt AC 79 ms 2688 KB
1_014.txt AC 79 ms 2688 KB
1_015.txt AC 80 ms 2688 KB
1_016.txt AC 77 ms 2688 KB
1_017.txt AC 76 ms 2688 KB
1_018.txt AC 72 ms 2688 KB
1_019.txt AC 63 ms 2560 KB
1_020.txt AC 60 ms 2560 KB