結果
| 問題 |
No.3241 Make Multiplication of 8
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-22 21:11:56 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 149 ms / 2,000 ms |
| コード長 | 3,822 bytes |
| コンパイル時間 | 2,677 ms |
| コンパイル使用メモリ | 82,184 KB |
| 実行使用メモリ | 47,564 KB |
| 最終ジャッジ日時 | 2025-08-22 21:12:04 |
| 合計ジャッジ時間 | 6,475 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 23 |
ソースコード
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Set;
class FastScanner {
private static FastScanner instance = null;
private final InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private FastScanner() {} // 外部から new できないようにする
public static FastScanner getInstance() {
if (instance == null) {
instance = new FastScanner();
}
return instance;
}
private boolean hasNextByte() {
if (ptr < buflen) return true;
ptr = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
return buflen > 0;
}
private int readByte() {
if (hasNextByte()) return buffer[ptr++];
else return -1;
}
private boolean isPrintableChar(int c) {
return 33 <= c && c <= 126;
}
public boolean hasNext() {
while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
return hasNextByte();
}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
while (b >= '0' && b <= '9') {
n = n * 10 + (b - '0');
b = readByte();
}
return minus ? -n : n;
}
public int nextInt() {
return (int) nextLong();
}
public long[] nextLongs(int n) {
long[] a = new long[n];
for (int i = 0; i < n; ++i) {
a[i] = nextLong();
}
return a;
}
public int[] nextInts(int n) {
int[] a = new int[n];
for (int i = 0; i < n; ++i) {
a[i] = nextInt();
}
return a;
}
}
class MyPrintWriter extends PrintWriter {
public MyPrintWriter(PrintStream out) {
super(out);
}
public void print(long[] a) {
print(a, " ");
}
public void print(int[] a) {
print(a, " ");
}
public void print(int[] a, String separator) {
for (int i = 0; i < a.length; ++i) {
super.print(a[i]+(i==a.length-1?"\n":separator));
}
}
public void print(long[] a, String separator) {
for (int i = 0; i < a.length; ++i) {
super.print(a[i]+(i==a.length-1?"\n":separator));
}
}
public void printlnYesNo(boolean flag) {
println(flag?"Yes":"No");
}
}
class Main implements Runnable { // Runnableを実装する
public static void main(String[] args) {
new Thread(null, new Main(), "", 1024 * 1024 * 1024).start(); // 1024MBスタックを確保して実行
}
public void run() {
FastScanner sc = FastScanner.getInstance();
MyPrintWriter pw = new MyPrintWriter(System.out);
int N=sc.nextInt();
long[]f=new long[4];
long ans=0;
for(int i=0;i<N;++i) {
long A=sc.nextLong();
long B=sc.nextLong();
int e=0;
while(A>0&&A%2==0) {
++e;
A/=2;
}
if(e==0)continue;
if(e>=3)ans+=B;
else f[e]+=B;
}
{
long m=Math.min(f[1], f[2]);
ans+=m;
f[1]-=m;
f[2]-=m;
ans+=f[1]/3;
ans+=f[2]/2;
}
System.out.println(ans);
pw.close();
}
static void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}