結果

問題 No.1006 Share an Integer
ユーザー どららどらら
提出日時 2020-03-06 22:31:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,005 bytes
コンパイル時間 1,845 ms
コンパイル使用メモリ 166,916 KB
実行使用メモリ 16,768 KB
最終ジャッジ日時 2024-04-22 08:57:02
合計ジャッジ時間 8,183 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
16,768 KB
testcase_01 AC 4 ms
11,384 KB
testcase_02 AC 6 ms
11,484 KB
testcase_03 AC 5 ms
11,436 KB
testcase_04 AC 5 ms
11,240 KB
testcase_05 AC 5 ms
11,392 KB
testcase_06 AC 5 ms
11,392 KB
testcase_07 AC 5 ms
11,376 KB
testcase_08 AC 6 ms
11,392 KB
testcase_09 AC 6 ms
11,264 KB
testcase_10 AC 5 ms
11,428 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int divisor(int)':
main.cpp:17:10: warning: 'ret' may be used uninitialized [-Wmaybe-uninitialized]
   17 |       ret++;
      |       ~~~^~
main.cpp:14:7: note: 'ret' was declared here
   14 |   int ret;
      |       ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int memo[2000005];

int divisor(int n){
  if(memo[n] != -1) return memo[n];
  int ret;
  for(int i=1; i*i<=n; i++){
    if(n%i==0){
      ret++;
      if(i!=n/i) ret++;
    }
  }
  return memo[n] = ret;
}

int main(){
  rep(i,2000005) memo[i] = -1;

  int X;
  cin >> X;

  int val = 1 << 30;
  vector<pair<int,int>> v;
  
  REP(i,1,X){
    int A = i;
    int B = X - A;

    int fA = A - divisor(A);
    int fB = B - divisor(B);
    int diff = abs(fA-fB);

    if(val == diff){
      v.emplace_back(A,B);
    }
    else if(val > diff){
      val = diff;
      v.clear();
      v.emplace_back(A,B);
    }
  }

  rep(i,v.size()){
    cout << v[i].first << " " << v[i].second << endl;
  }
  
  return 0;
}
0