結果

問題 No.1006 Share an Integer
ユーザー Tsukasan_z46Tsukasan_z46
提出日時 2020-06-21 14:55:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,322 ms / 2,000 ms
コード長 1,519 bytes
コンパイル時間 2,367 ms
コンパイル使用メモリ 214,840 KB
実行使用メモリ 28,736 KB
最終ジャッジ日時 2023-09-16 18:25:08
合計ジャッジ時間 14,709 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 629 ms
25,500 KB
testcase_12 AC 1,212 ms
27,072 KB
testcase_13 AC 1,311 ms
27,964 KB
testcase_14 AC 1,318 ms
28,736 KB
testcase_15 AC 1,102 ms
27,988 KB
testcase_16 AC 448 ms
16,128 KB
testcase_17 AC 666 ms
25,196 KB
testcase_18 AC 1,105 ms
26,316 KB
testcase_19 AC 1,031 ms
26,652 KB
testcase_20 AC 1,131 ms
27,476 KB
testcase_21 AC 1,322 ms
27,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// yukicoder No.1006 Share an Integer
// 2020.06.21

vector<int> XX;
// auto MP = PrimeFac(N);
// for(auto i : MP){
//   cout << i.first << " " << i.second << endl;
// }
map<int, int> PrimeFac(int n){
  map<int, int> mp;
  int cnt = 0;
  while(n%2 == 0){
    n /= 2;
    cnt++;
  }
  if(cnt != 0) mp[2] = cnt;
  for(int i = 3; i*i <= n; i += 2){
    cnt = 0;
    while(n%i == 0){
      n /= i;
      cnt++;
    }
    if(cnt != 0) mp[i] = cnt;
  }
  if(n != 1) mp[n] = 1;
  return mp;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int X; cin >> X;
  XX.assign(X, 1e9);
  XX[1] = 0;
  for(int i = 2; i < X; i++){
    auto x = PrimeFac(i);
    int res = 1;
    for(auto j : x){
      res *= j.second+1;
    }
    XX[i] = abs(i-res);
  }
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int> > > pq;
  for(int i = 1; i < X; i++){
    pq.push({abs(XX[i]-XX[X-i]),i});
  }
  bool flag = true;
  int minV = 1e9;
  while(flag && !pq.empty()){
    auto cur = pq.top(); pq.pop();
    if(cur.first <= minV){
      minV = cur.first;
      cout << cur.second << " " << X-cur.second << endl;
    }else{
      flag = false;
    }
  }
}
0