CODE FESTIVAL 2016 qual C

Submission #1694565

Source codeソースコード

#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <sstream>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
template <class T> inline void smin(T &a, T const &b) { a = min(a, b); }
template <class T> inline void smax(T &a, T const &b) { a = max(a, b); }

#ifdef LOCAL
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        print_to(os, ", ", "\n", __VA_ARGS__);            \
        std::cerr << os.str();                            \
    } while (0)
#define dump_(a)                                          \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #a << " = [";          \
        print_to_(os, ", ", "]\n", all(a));               \
        std::cerr << os.str();                            \
    } while (0)
#else
#define dump(...)
#define dump_(...)
#endif

template <typename T>
void print_to(std::ostream &os, const char *, const char *tail, const T &fst) {
    os << fst << tail;
}
template <typename Fst, typename... Rst>
void print_to(std::ostream &os, const char *del, const char *tail, const Fst &fst, const Rst &... rst) {
    os << fst << del;
    print_to(os, del, tail, rst...);
}
template <typename Iter>
void print_to_(std::ostream &os, const char *del, const char *tail, Iter bgn, Iter end) {
    for (Iter it = bgn; it != end;) {
        os << *it;
        if (++it != end) {
            os << del;
        } else {
            os << tail;
        }
    }
}
template <typename Fst, typename... Rst>
void println(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, "\n", "\n", fst, rst...);
}
template <typename Fst, typename... Rst>
void print(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, " ", "\n", fst, rst...);
}
template <typename Iter>
void println_(Iter bgn, Iter end) {
    print_to_(std::cout, "\n", "\n", bgn, end);
}
template <typename Iter>
void print_(Iter bgn, Iter end) {
    print_to_(std::cout, " ", "\n", bgn, end);
}

// const int MOD = 1000000007;
namespace trush {
    int _ = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0),
             std::ios::sync_with_stdio(0), 0);
}

int N;
int T[101010], A[101010];
int X[101010];  //確定した値
int ma[101010]; //確定していないところの最大値

signed main()
{
    cin >> N;
    REP(i,N) cin >> T[i];
    REP(i,N) cin >> A[i];
    
    if (T[N-1] != A[0]) {
        cout << 0 << endl;
        return 0;
    }

    REP(i,101010) ma[i] = INF;

    X[0] = T[0];
    for (int i=1; i<N; i++) {
        if (T[i-1] < T[i]) X[i] = T[i];
        else ma[i] = T[i];
    }

    if (X[N-1] != 0 && X[N-1] != A[N-1]) {
        cout << 0 << endl;
        return 0;
    } else {
        X[N-1] = A[N-1];
    }
    for (int i=N-2; i>=0; i--) {
        if (A[i] > A[i+1]) {
            if (X[i] != 0 && X[i] != A[i]) {
                cout << 0 << endl;
                return 0;
            } else {
                if (ma[i] != INF && ma[i] < A[i]) {
                    cout << 0 << endl;
                    return 0;
                }
                X[i] = A[i];
            }
        } else {
            ma[i] = min(ma[i], A[i]);
        }
    }

    /*
    REP(i,N) {
        cout << X[i] << " ";
    }
    cout << endl;
    */

    int ans = 1;
    REP(i,N) {
        //cout << ma[i] << " ";
        if (X[i] == 0) {
            ans *= ma[i];
            ans %= MOD;
        }
    }
    //cout << endl;
    cout << ans << endl;
}

Submission

Task問題 C - 二人のアルピニスト / Two Alpinists
User nameユーザ名 hiyokko2
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 400
Source lengthソースコード長 4260 Byte
File nameファイル名
Exec time実行時間 23 ms
Memory usageメモリ使用量 3456 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 2 ms 1024 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 2 ms 1024 KB
0_003.txt AC 2 ms 1024 KB
1_004.txt AC 1 ms 256 KB
1_005.txt AC 2 ms 1024 KB
1_006.txt AC 2 ms 1024 KB
1_007.txt AC 2 ms 1024 KB
1_008.txt AC 23 ms 2688 KB
1_009.txt AC 20 ms 3456 KB
1_010.txt AC 22 ms 3200 KB
1_011.txt AC 23 ms 3200 KB
1_012.txt AC 22 ms 3456 KB
1_013.txt AC 22 ms 3200 KB
1_014.txt AC 22 ms 3456 KB
1_015.txt AC 22 ms 2944 KB
1_016.txt AC 22 ms 3456 KB
1_017.txt AC 21 ms 2688 KB
1_018.txt AC 20 ms 2688 KB
1_019.txt AC 19 ms 2688 KB
1_020.txt AC 18 ms 2688 KB