Submission #8777300


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, A[101010];
int cnt[101010];
//---------------------------------------------------------------------------------------------------
mint solve() {
	mint ans = 1;
	rep(i, 0, N) A[i]++;
	cnt[0] = 3;
	rep(i, 0, N) {
		if (0 < cnt[A[i] - 1]) {
			ans *= cnt[A[i] - 1];
			cnt[A[i] - 1]--;
			cnt[A[i]]++;
		}
		else return 0;
	}
	return ans;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	cout << solve() << endl;
}





Submission Info

Submission Time
Task E - Colorful Hats 2
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 500
Code Size 3507 Byte
Status
Exec Time 10 ms
Memory 1024 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt
All 500 / 500 in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in59.txt, in61.txt, in62.txt, in63.txt, in64.txt, in65.txt, in66.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
in01.txt 1 ms 256 KB
in02.txt 9 ms 640 KB
in03.txt 1 ms 256 KB
in04.txt 1 ms 256 KB
in05.txt 9 ms 768 KB
in06.txt 9 ms 768 KB
in07.txt 9 ms 768 KB
in08.txt 9 ms 768 KB
in09.txt 1 ms 256 KB
in10.txt 9 ms 640 KB
in11.txt 1 ms 256 KB
in12.txt 1 ms 256 KB
in13.txt 9 ms 768 KB
in14.txt 9 ms 768 KB
in15.txt 10 ms 1024 KB
in16.txt 9 ms 896 KB
in17.txt 9 ms 768 KB
in18.txt 7 ms 640 KB
in19.txt 1 ms 256 KB
in20.txt 1 ms 256 KB
in21.txt 2 ms 384 KB
in22.txt 9 ms 768 KB
in23.txt 9 ms 768 KB
in24.txt 9 ms 768 KB
in59.txt 1 ms 256 KB
in61.txt 1 ms 256 KB
in62.txt 1 ms 256 KB
in63.txt 1 ms 256 KB
in64.txt 1 ms 256 KB
in65.txt 1 ms 256 KB
in66.txt 1 ms 256 KB
sample_01.txt 1 ms 256 KB
sample_02.txt 1 ms 256 KB
sample_03.txt 1 ms 256 KB