結果

問題 No.1006 Share an Integer
ユーザー Tsukasan_z46Tsukasan_z46
提出日時 2020-06-21 14:52:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,504 bytes
コンパイル時間 2,341 ms
コンパイル使用メモリ 213,328 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-16 18:22:06
合計ジャッジ時間 6,172 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

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){
    auto cur = pq.top(); pq.pop();
    if(cur.first <= minV){
      minV = cur.first;
      cout << cur.second << " " << X-cur.second << endl;
    }else{
      flag = false;
    }
  }
}
0