답안 #19828

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19828 2016-02-25T06:04:06 Z xhae 동전 (kriii4_E) C++14
100 / 100
154 ms 2744 KB
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

const int mmod = 1000000007;

int prv[256][512]; // successive previous H, current grundy
int nxt[256][512];

vector<int> grundy;

void run_init(int n)
{
  for (int i=0; i<256; i++)
    for (int j=0; j<512; j++)
      prv[i][j] = nxt[i][j] = 0;

  prv[0][0] = 1;

  for (int i=0; i<=n; i++) {
    for (int j=0; j<=i; j++)
      for (int k=0; k<512; k++) {
        if (i < n) {
          // H
          nxt[j+1][k] = (nxt[j+1][k] + prv[j][k]) % mmod;
        }
        if (j < n) {
          // T
          nxt[0][k^grundy[j]] = (nxt[0][k^grundy[j]] + prv[j][k]) % mmod;
        }
      }

    for (int j=0; j<256; j++)
      for (int k=0; k<512; k++) prv[j][k] = nxt[j][k], nxt[j][k] = 0;
  }

}

void run_grundy(int n)
{
  for (int i=0; i<256; i++)
    for (int j=0; j<512; j++)
      prv[i][j] = nxt[i][j] = 0;

  prv[0][0] = 1;

  for (int i=0; i<=n; i++) {
    for (int j=0; j<=i; j++)
      for (int k=0; k<512; k++) {
        if (i < n) {
          // H
          nxt[j+1][k] = (nxt[j+1][k] + prv[j][k]) % mmod;
        }
        {
          // T
          nxt[0][k^grundy[j]] = (nxt[0][k^grundy[j]] + prv[j][k]) % mmod;
        }
      }

    for (int j=0; j<256; j++)
      for (int k=0; k<512; k++) prv[j][k] = nxt[j][k], nxt[j][k] = 0;
  }

}

int main()
{
  int n;
  cin >> n;

  grundy.push_back(0);
  for (int i=1; i<=n; i++) {
/*    run_init(i);

    int ii = 0;
    while (prv[0][ii]) ii ++;
    grundy.push_back(ii);*/
    grundy.push_back(i);
  }

/*  for (int i=0; i<=n; i++) printf("%d ", grundy[i]);
  printf("\n");
  return 0;*/

  run_grundy(n);

  printf("%d\n", prv[0][0]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2744 KB Output is correct
2 Correct 0 ms 2744 KB Output is correct
3 Correct 0 ms 2744 KB Output is correct
4 Correct 0 ms 2744 KB Output is correct
5 Correct 0 ms 2744 KB Output is correct
6 Correct 2 ms 2744 KB Output is correct
7 Correct 0 ms 2744 KB Output is correct
8 Correct 0 ms 2744 KB Output is correct
9 Correct 3 ms 2744 KB Output is correct
10 Correct 3 ms 2744 KB Output is correct
11 Correct 3 ms 2744 KB Output is correct
12 Correct 0 ms 2744 KB Output is correct
13 Correct 4 ms 2744 KB Output is correct
14 Correct 4 ms 2744 KB Output is correct
15 Correct 2 ms 2744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 2744 KB Output is correct
2 Correct 82 ms 2744 KB Output is correct
3 Correct 11 ms 2744 KB Output is correct
4 Correct 32 ms 2744 KB Output is correct
5 Correct 23 ms 2744 KB Output is correct
6 Correct 41 ms 2744 KB Output is correct
7 Correct 113 ms 2744 KB Output is correct
8 Correct 134 ms 2744 KB Output is correct
9 Correct 53 ms 2744 KB Output is correct
10 Correct 130 ms 2744 KB Output is correct
11 Correct 35 ms 2744 KB Output is correct
12 Correct 33 ms 2744 KB Output is correct
13 Correct 123 ms 2744 KB Output is correct
14 Correct 89 ms 2744 KB Output is correct
15 Correct 52 ms 2744 KB Output is correct
16 Correct 14 ms 2744 KB Output is correct
17 Correct 151 ms 2744 KB Output is correct
18 Correct 15 ms 2744 KB Output is correct
19 Correct 80 ms 2744 KB Output is correct
20 Correct 21 ms 2744 KB Output is correct
21 Correct 103 ms 2744 KB Output is correct
22 Correct 85 ms 2744 KB Output is correct
23 Correct 63 ms 2744 KB Output is correct
24 Correct 45 ms 2744 KB Output is correct
25 Correct 30 ms 2744 KB Output is correct
26 Correct 10 ms 2744 KB Output is correct
27 Correct 123 ms 2744 KB Output is correct
28 Correct 10 ms 2744 KB Output is correct
29 Correct 121 ms 2744 KB Output is correct
30 Correct 154 ms 2744 KB Output is correct