AtCoder Regular Contest 044

Submission #1061453

Source codeソースコード

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

ll mod = 1e9 + 7;

ll po(ll k, ll x) {
  if (x == 0) {
    return 1;
  }
  if (x == 1) {
    return k % mod;
  }
  ll y = po(k, x/2);
  y = y * y % mod;
  if (x % 2 == 1) {
    y = y * k % mod;
  }
  return y;
}

ll po2(ll x) {
  return po(2, x);
}

ll po2_1(ll x) {
  ll ret = po2(x);
  ret = (ret + mod - 1) % mod;
  return ret;
}

int main() {
  int n;
  scanf("%d", &n);
  vi a(n);
  rep (i, n) {
    scanf("%d", &a[i]);
  }
  bool possible = true;
  if (a[0] != 0) {
    possible = false;
  }
  int maxi = 0;
  FOR (i, 1, n) {
    if (a[i] == 0) {
      possible = false;
    }
    maxi = max(maxi, a[i]);
  }

  vi gr(maxi+1, 0);
  rep (i, n) {
    gr[a[i]] += 1;
  }
  FOR (i, 1, maxi+1) {
    if (gr[i] == 0) {
      possible = false;
    }
  }
  if (!possible) {
    printf("0\n");
    return 0;
  }

  ll ans = 1;
  FOR (i, 1, maxi+1) {
    ll connect = po2_1(gr[i-1]);
    connect = po(connect, gr[i]);
    ans = ans * connect % mod;
    ll comb = (ll)gr[i] * (gr[i]-1) / 2 % (mod - 1);
    ans = ans * po2(comb) % mod;
  }
  printf("%lld\n", ans);

  return 0;
}

Submission

Task問題 B - 最短路問題
User nameユーザ名 gosenoku
Created time投稿日時
Language言語 C++14 (Clang++ 3.4)
Status状態 AC
Score得点 100
Source lengthソースコード長 2044 Byte
File nameファイル名
Exec time実行時間 36 ms
Memory usageメモリ使用量 1572 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt
All 100 / 100 sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt,test_01.txt,test_02.txt,test_03.txt,test_04.txt,test_05.txt,test_06.txt,test_07.txt,test_08.txt,test_09.txt,test_10.txt,test_11.txt,test_12.txt,test_13.txt,test_14.txt,test_15.txt,test_16.txt,test_17.txt,test_18.txt,test_19.txt,test_20.txt,test_21.txt,test_22.txt,test_23.txt,test_24.txt,test_25.txt,test_26.txt,test_27.txt,test_28.txt,test_29.txt,test_30.txt,test_31.txt,test_32.txt,test_33.txt,test_34.txt,test_35.txt,test_36.txt,test_37.txt,test_38.txt,test_39.txt,test_40.txt,test_41.txt,test_42.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 19 ms 928 KB
sample_02.txt AC 17 ms 800 KB
sample_03.txt AC 18 ms 844 KB
sample_04.txt AC 18 ms 924 KB
test_01.txt AC 17 ms 924 KB
test_02.txt AC 17 ms 928 KB
test_03.txt AC 16 ms 928 KB
test_04.txt AC 16 ms 800 KB
test_05.txt AC 18 ms 928 KB
test_06.txt AC 18 ms 924 KB
test_07.txt AC 16 ms 800 KB
test_08.txt AC 18 ms 800 KB
test_09.txt AC 16 ms 920 KB
test_10.txt AC 18 ms 800 KB
test_11.txt AC 26 ms 1312 KB
test_12.txt AC 24 ms 1180 KB
test_13.txt AC 24 ms 1184 KB
test_14.txt AC 24 ms 1176 KB
test_15.txt AC 25 ms 1224 KB
test_16.txt AC 26 ms 1308 KB
test_17.txt AC 23 ms 1180 KB
test_18.txt AC 24 ms 1184 KB
test_19.txt AC 25 ms 1176 KB
test_20.txt AC 25 ms 1308 KB
test_21.txt AC 26 ms 1180 KB
test_22.txt AC 27 ms 1308 KB
test_23.txt AC 25 ms 1184 KB
test_24.txt AC 28 ms 1184 KB
test_25.txt AC 32 ms 1268 KB
test_26.txt AC 34 ms 1524 KB
test_27.txt AC 36 ms 1572 KB
test_28.txt AC 33 ms 1304 KB
test_29.txt AC 29 ms 1316 KB
test_30.txt AC 25 ms 1180 KB
test_31.txt AC 18 ms 844 KB
test_32.txt AC 18 ms 920 KB
test_33.txt AC 18 ms 928 KB
test_34.txt AC 18 ms 800 KB
test_35.txt AC 17 ms 788 KB
test_36.txt AC 18 ms 800 KB
test_37.txt AC 18 ms 800 KB
test_38.txt AC 18 ms 916 KB
test_39.txt AC 18 ms 920 KB
test_40.txt AC 18 ms 800 KB
test_41.txt AC 18 ms 928 KB
test_42.txt AC 18 ms 920 KB