CODE FESTIVAL 2016 Final

Submission #1336602

Source codeソースコード

#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int64, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

map<int64, int64> dp;
int64 n, m;
vector<int64> f;

vector<int64> factor(int64 n) {
  vector<int64> ret;
  for (int64 i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      while (n % i == 0) {
        n /= i;
      }
      ret.push_back(i);
    }
  }
  if (n > 1) ret.push_back(n);
  return ret;
}

int64 solve(int64 n);

void DFS(int now, vector<ii>& can, int64 prod, int64 n, int64& ret) {
  if (now == can.size()) {
    if (prod == 1 || prod == n) return;
    ret = min(ret, solve(prod) + solve(n / prod) + m);
    return;
  }
  int64 cur = prod;
  for (int i = 0; i <= can[now].second; ++i) {
    DFS(now + 1, can, cur, n, ret);
    cur *= can[now].first;
  }
}

int64 solve(int64 n) {
  if (dp.find(n) != dp.end()) {
    return dp[n];
  }
  int64 ret = n;
  vector<ii> can;
  for (auto& p : f) {
    if (n % p == 0) {
      int cnt = 0;
      for (int64 m = n; m % p == 0; m /= p) ++cnt;
      can.push_back({p, cnt});
    }
  }
  DFS(0, can, 1, n, ret);
  dp.insert({n, ret});
  return ret;
}

int main() {
  scanf("%lld%lld", &n, &m);
  f = factor(n);
  printf("%lld\n", solve(n));
  return 0;
}

Submission

Task問題 E - Cookies
User nameユーザ名 cuiaoxiang
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 2104 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:93:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &n, &m);
^

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt,sample-03.txt
dataset1 0 / 500 sample-01.txt,01-01.txt,01-02.txt,01-03.txt,01-04.txt,01-05.txt,01-06.txt,01-07.txt,01-08.txt,01-09.txt,01-10.txt,01-11.txt,01-12.txt,01-13.txt,01-14.txt,01-15.txt,01-16.txt,01-17.txt,01-18.txt,01-19.txt,01-20.txt,01-21.txt,01-22.txt,01-23.txt,01-24.txt,01-25.txt,01-26.txt
dataset2 0 / 500 sample-01.txt,sample-02.txt,sample-03.txt,01-01.txt,01-02.txt,01-03.txt,01-04.txt,01-05.txt,01-06.txt,01-07.txt,01-08.txt,01-09.txt,01-10.txt,01-11.txt,01-12.txt,01-13.txt,01-14.txt,01-15.txt,01-16.txt,01-17.txt,01-18.txt,01-19.txt,01-20.txt,01-21.txt,01-22.txt,01-23.txt,01-24.txt,01-25.txt,01-26.txt,02-01.txt,02-02.txt,02-03.txt,02-04.txt,02-05.txt,02-06.txt,02-07.txt,02-08.txt,02-09.txt,02-10.txt,02-11.txt,02-12.txt,02-13.txt,02-14.txt,02-15.txt,02-16.txt,02-17.txt,02-18.txt,02-19.txt,02-20.txt,02-21.txt,02-22.txt,02-23.txt,02-24.txt,02-25.txt,02-26.txt,02-27.txt,02-28.txt,02-29.txt,02-30.txt,02-31.txt,02-32.txt,02-33.txt,02-34.txt,02-35.txt,02-36.txt,02-37.txt,02-38.txt,02-39.txt,02-40.txt,sample-01.txt,sample-02.txt,sample-03.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt WA
01-02.txt WA
01-03.txt AC 1 ms 256 KB
01-04.txt AC 1 ms 256 KB
01-05.txt AC 1 ms 256 KB
01-06.txt AC 1 ms 256 KB
01-07.txt AC 1 ms 256 KB
01-08.txt AC 1 ms 256 KB
01-09.txt WA
01-10.txt WA
01-11.txt AC 1 ms 256 KB
01-12.txt AC 1 ms 256 KB
01-13.txt AC 1 ms 256 KB
01-14.txt WA
01-15.txt WA
01-16.txt AC 1 ms 256 KB
01-17.txt WA
01-18.txt AC 1 ms 256 KB
01-19.txt WA
01-20.txt AC 1 ms 256 KB
01-21.txt AC 1 ms 256 KB
01-22.txt AC 1 ms 256 KB
01-23.txt AC 1 ms 256 KB
01-24.txt AC 1 ms 256 KB
01-25.txt AC 1 ms 256 KB
01-26.txt AC 1 ms 256 KB
02-01.txt AC 1 ms 256 KB
02-02.txt WA
02-03.txt WA
02-04.txt AC 2 ms 256 KB
02-05.txt AC 2 ms 256 KB
02-06.txt WA
02-07.txt WA
02-08.txt WA
02-09.txt WA
02-10.txt WA
02-11.txt WA
02-12.txt AC 2 ms 256 KB
02-13.txt AC 2 ms 256 KB
02-14.txt WA
02-15.txt WA
02-16.txt WA
02-17.txt WA
02-18.txt WA
02-19.txt AC 2 ms 256 KB
02-20.txt AC 2 ms 256 KB
02-21.txt AC 2 ms 256 KB
02-22.txt AC 2 ms 256 KB
02-23.txt AC 2 ms 256 KB
02-24.txt AC 2 ms 256 KB
02-25.txt WA
02-26.txt WA
02-27.txt AC 1 ms 256 KB
02-28.txt AC 1 ms 256 KB
02-29.txt WA
02-30.txt WA
02-31.txt WA
02-32.txt WA
02-33.txt WA
02-34.txt WA
02-35.txt WA
02-36.txt WA
02-37.txt WA
02-38.txt WA
02-39.txt WA
02-40.txt WA
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 2 ms 256 KB
sample-03.txt WA