結果

問題 No.1006 Share an Integer
ユーザー iqueue02iqueue02
提出日時 2020-03-06 22:15:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,217 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 170,756 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-22 08:21:49
合計ジャッジ時間 5,196 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 TLE -
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>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9;
vector<long long> divisor(long long n){
    vector<long long> res;
    for(long long i = 1; i*i <= n; i++){
        if(n%i==0){
            res.push_back(i);
            if(n/i != i)res.push_back(n/i);
        }
    }
    return res;
}

int main(){
  int x;
  cin >> x;
  set<P> st;
  int mi = INF;

  for (int a = 1; a + a <= x; a++) {
    int b = x - a;  
    auto d1 = divisor(a);
    auto d2 = divisor(b);
    int f1 = a - d1.size(), f2 = b - d2.size();
    int v = abs(f1 - f2);

    if (v < mi) mi = v;
  }
  vector<P> res1, res2;
  for (int a = 1; a + a <= x; a++) {
    int b = x - a;  
    auto d1 = divisor(a);
    auto d2 = divisor(b);
    int f1 = a - d1.size(), f2 = b - d2.size();
    int v = abs(f1 - f2);

    if (v == mi) {
      res1.emplace_back(make_pair(a, b));
      res2.emplace_back(make_pair(b, a));
    }
  }
  reverse(res2.begin(), res2.end());
  for (auto e : res1) {
    printf("%d %d\n", e.first, e.second);
  }
  for (auto e : res2) {
    printf("%d %d\n", e.first, e.second);
  }

  return 0;
}
0