AtCoder Regular Contest 066

Submission #1033439

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 <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 eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#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 > >;
typedef pair<ll, ll> pll;

int mod = 1e9 + 7;

map<pll, bool> calculated;
map<pll, ll> f;

ll func(ll s, ll x) {
  if (s == 0) {
    return 1;
  }
  if (s == 1) {
    if (x == 0) {
      return 1;
    } else {
      return 2;
    }
  }
  if (x == 0) {
    return (1 + s / 2) % mod;
  }
  auto mpsx = mp(s, x);
  if (calculated[mpsx]) {
    return f[mpsx];
  }
  f[mpsx] = (func(s/2, x/2) + func((s-1)/2, (x-1)/2) + func((s-2)/2, x/2)) % mod;
  calculated[mpsx] = true;
  return f[mpsx];
}

int main() {
  ll n;
  scanf("%lld", &n);
  ll ans = func(n, n);
  
  printf("%lld\n", ans);
  return 0;
}

Submission

Task問題 D - Xor Sum
User nameユーザ名 cyglef
Created time投稿日時
Language言語 C++14 (Clang 3.8.0)
Status状態 AC
Score得点 600
Source lengthソースコード長 1598 Byte
File nameファイル名
Exec time実行時間 5 ms
Memory usageメモリ使用量 504 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt
All 600 / 600 subtask_1_max_01.txt,subtask_1_rand_01.txt,subtask_1_rand_02.txt,subtask_1_rand_03.txt,subtask_1_rand_04.txt,subtask_1_rand_05.txt,subtask_1_small_rand_01.txt,subtask_1_small_rand_02.txt,subtask_1_small_rand_03.txt,subtask_1_small_rand_04.txt,subtask_1_small_rand_05.txt,subtask_1_specific_01.txt,subtask_1_specific_02.txt,subtask_1_specific_03.txt,subtask_1_specific_04.txt,subtask_1_specific_05.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 5 ms 504 KB
sample_02.txt AC 3 ms 256 KB
sample_03.txt AC 3 ms 256 KB
subtask_1_max_01.txt AC 3 ms 256 KB
subtask_1_rand_01.txt AC 3 ms 256 KB
subtask_1_rand_02.txt AC 3 ms 256 KB
subtask_1_rand_03.txt AC 3 ms 256 KB
subtask_1_rand_04.txt AC 3 ms 256 KB
subtask_1_rand_05.txt AC 3 ms 256 KB
subtask_1_small_rand_01.txt AC 3 ms 256 KB
subtask_1_small_rand_02.txt AC 3 ms 256 KB
subtask_1_small_rand_03.txt AC 3 ms 256 KB
subtask_1_small_rand_04.txt AC 3 ms 256 KB
subtask_1_small_rand_05.txt AC 3 ms 256 KB
subtask_1_specific_01.txt AC 3 ms 256 KB
subtask_1_specific_02.txt AC 3 ms 256 KB
subtask_1_specific_03.txt AC 3 ms 256 KB
subtask_1_specific_04.txt AC 3 ms 256 KB
subtask_1_specific_05.txt AC 3 ms 256 KB