結果

問題 No.906 Y字グラフ
ユーザー RTnFRTnF
提出日時 2019-11-29 10:32:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 5,555 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 202,620 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-20 21:17:33
合計ジャッジ時間 3,171 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,820 KB
testcase_01 AC 3 ms
6,820 KB
testcase_02 AC 3 ms
6,816 KB
testcase_03 AC 3 ms
6,816 KB
testcase_04 AC 3 ms
6,816 KB
testcase_05 AC 3 ms
6,820 KB
testcase_06 AC 3 ms
6,820 KB
testcase_07 AC 2 ms
6,816 KB
testcase_08 AC 3 ms
6,820 KB
testcase_09 AC 3 ms
6,816 KB
testcase_10 AC 4 ms
6,820 KB
testcase_11 AC 3 ms
6,820 KB
testcase_12 AC 4 ms
6,820 KB
testcase_13 AC 3 ms
6,820 KB
testcase_14 AC 3 ms
6,816 KB
testcase_15 AC 3 ms
6,816 KB
testcase_16 AC 3 ms
6,820 KB
testcase_17 AC 4 ms
6,820 KB
testcase_18 AC 3 ms
6,820 KB
testcase_19 AC 3 ms
6,816 KB
testcase_20 AC 4 ms
6,816 KB
testcase_21 AC 3 ms
6,816 KB
testcase_22 AC 2 ms
6,816 KB
testcase_23 AC 3 ms
6,820 KB
testcase_24 AC 4 ms
6,820 KB
testcase_25 AC 4 ms
6,816 KB
testcase_26 AC 2 ms
6,816 KB
testcase_27 AC 3 ms
6,820 KB
testcase_28 AC 2 ms
6,816 KB
testcase_29 AC 3 ms
6,820 KB
testcase_30 AC 4 ms
6,816 KB
testcase_31 AC 4 ms
6,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for(ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
template<typename T> void print(const T &x){ cout << x << endl; }
template<typename T> void print(const vector<T> &x){ rep(i, SZ(x)){ cout << x[i] << " \n"[i+1==SZ(x)]; } cout << flush; }
template<typename T> void print(const vector<T> &x, ll s, ll n){ repr(i, s, n){ cout << x[i] << " \n"[i+1==n]; } cout << flush; }
template<typename T> void printv(const vector<T> &x){ rep(i, SZ(x)){ cout << x[i] << "\n"; } cout << flush; }
template<typename T> void printv(const vector<T> &x, ll s, ll n){ repr(i, s, n){ cout << x[i] << "\n"; } cout << flush; }
template<typename T> void print(const vector<vector<T>> &x){ rep(i, SZ(x)){ rep(j, SZ(x[i])){ cout << x[i][j] << " \n"[j+1==SZ(x[i])]; } } cout << flush; }
template<typename T> void print(const vector<vector<T>> &x, ll s1, ll n1, ll s2, ll n2){ repr(i, s1, n1){ repr(j, s2, n2){ cout << x[i][j] << " \n"[j+1==n2]; } } cout << flush; }
template<typename T, size_t S> void print(const T (&x)[S], ll s = 0, ll n = S){ repr(i, s, n){ cout << x[i] << " \n"[i+1==n]; } cout << flush; }
template<typename T, size_t S> void printv(const T (&x)[S], ll s = 0, ll n = S){ repr(i, s, n){ cout << x[i] << "\n"; } cout << flush; }
template<typename T, size_t S1, size_t S2> void print(const T (&x)[S1][S2], ll s1 = 0, ll n1 = S1, ll s2 = 0, ll n2 = S2){ repr(i, s1, n1){ repr(j, s2, n2){ cout << x[i][j] << " \n"[j+1==n2]; } } cout << flush; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
// ModInt
// 参考:https://ei1333.github.io/luzhiled/snippets/math/mod-int.html
// modはコンパイル時に決定
template<ll mod> struct ModInt {
    ll x;
    ModInt() : x(0) {}
    ModInt(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}
    constexpr ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt &p){
        x = x * p.x % mod;
        return *this;
    }
    constexpr ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    constexpr ModInt operator-(){ return ModInt(-x); }
    constexpr ModInt operator+(const ModInt &p){ return ModInt(*this) += p; }
    constexpr ModInt operator-(const ModInt &p){ return ModInt(*this) -= p; }
    constexpr ModInt operator*(const ModInt &p){ return ModInt(*this) *= p; }
    constexpr ModInt operator/(const ModInt &p){ return ModInt(*this) /= p; }
    constexpr bool operator==(const ModInt &p){ return x == p.x; }
    constexpr bool operator!=(const ModInt &p){ return x != p.x; }
    constexpr ModInt inverse() const{
        ll a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    constexpr ModInt pow(ll n) {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt &a){
        ll t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }
};

using mint = ModInt<MOD>;
using vm = vector<mint>;
using vvm = vector<vm>;

const int MAX = 200010;
mint fac[MAX], facinv[MAX];
void combInit(){
    fac[0] = mint(1);
    facinv[0] = mint(1);
    for(int i = 0; i < MAX-1; i++){
        fac[i+1] = fac[i]*(i+1);
        facinv[i+1] = fac[i+1].inverse();
    }
}
mint comb(const ll a, const ll b){
    assert(a < MAX);
    assert(b < MAX);
    if(a < 0 || b < 0 || b > a){
        return mint(0);
    }
    mint ret(1);
    ret *= fac[a];
    ret *= facinv[b];
    ret *= facinv[a-b];
    return ret;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    n -= 4;
    mint m(n);
    mint all = (m+1)*(m+2)/2;
    mint pri = (n % 3 == 0 ? 1 : 0);
    mint sec = (n % 3 == 0 ? n/2 : n/2+1);
    mint ter = (all - pri - sec*3)/6;
    cout << pri+sec+ter << endl;
    return 0;
}
0