結果

問題 No.3241 Make Multiplication of 8
ユーザー tnakao0123
提出日時 2025-08-24 19:11:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 723 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 41,928 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-24 19:11:42
合計ジャッジ時間 2,376 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |     scanf("%d%d", &ai, &bi);
      |     ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3241.cc:  No.3241 Make Multiplication of 8 - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

/* typedef */

using ll = long long;

/* global variables */

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  ll cs[4] = {};
  for (int i = 0; i < n; i++) {
    int ai, bi;
    scanf("%d%d", &ai, &bi);

    int c = 0;
    while (! (ai & 1)) ai >>= 1, c++;

    if (c > 0) cs[min(3, c)] += bi;
  }
  //for (int i = 1; i <= 3; i++) printf(" %lld", cs[i]); putchar('\n');

  ll sum = cs[3];

  ll d = min(cs[1], cs[2]);
  sum += d, cs[1] -= d, cs[2] -= d;

  sum += cs[1] / 3 + cs[2] / 2;

  printf("%lld\n", sum);
  
  return 0;
}
0