結果

問題 No.1006 Share an Integer
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-03-07 02:34:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,671 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 88,192 KB
実行使用メモリ 18,848 KB
最終ジャッジ日時 2024-04-22 11:45:12
合計ジャッジ時間 2,538 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 47 ms
11,964 KB
testcase_12 AC 131 ms
17,956 KB
testcase_13 AC 134 ms
18,848 KB
testcase_14 AC 138 ms
18,800 KB
testcase_15 AC 105 ms
16,604 KB
testcase_16 AC 36 ms
9,848 KB
testcase_17 AC 52 ms
12,160 KB
testcase_18 AC 109 ms
16,768 KB
testcase_19 AC 96 ms
16,256 KB
testcase_20 AC 115 ms
17,152 KB
testcase_21 AC 133 ms
18,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,n)   for (int i = 0; i < (n); ++i)
#define sort(a)    sort((a).begin(), (a).end());
#define uniq(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define find(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));

  ll n; cin >> n;
  vector<ll> f(n + 1);
  for (int i = 1; i <= n; i++) f[i] = i;

  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      f[j]--;
    }
  }

  priority_queue<P, vector<P>, greater<P>> q;
  ll min = 100000000;
  for (int i = 1; i <= n / 2; i++) {
    ll sub = abs(f[i] - f[n - i]);

    if (sub < min) {
      q = decltype(q)();
      q.push(make_pair(i, n - i));
      if (i != n - i) q.push(make_pair(n - i, i));
      min = sub;
    } else if (sub == min) {
      q.push(make_pair(i, n - i));
      if (i != n - i) q.push(make_pair(n - i, i));
    }
  }

  while (!q.empty()) {
    cout << q.top().first << " " << q.top().second << endl;
    q.pop();
  }
}
0