結果

問題 No.1589 Bit Vector
ユーザー NASU41NASU41
提出日時 2021-07-09 00:00:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 12,047 bytes
コンパイル時間 2,888 ms
コンパイル使用メモリ 83,068 KB
実行使用メモリ 58,108 KB
最終ジャッジ日時 2024-07-01 13:22:20
合計ジャッジ時間 12,162 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
54,136 KB
testcase_01 AC 131 ms
53,840 KB
testcase_02 AC 113 ms
52,260 KB
testcase_03 AC 120 ms
53,020 KB
testcase_04 AC 126 ms
53,028 KB
testcase_05 AC 130 ms
53,492 KB
testcase_06 AC 127 ms
52,904 KB
testcase_07 AC 123 ms
52,540 KB
testcase_08 AC 123 ms
52,924 KB
testcase_09 AC 126 ms
53,916 KB
testcase_10 AC 129 ms
53,472 KB
testcase_11 AC 130 ms
53,480 KB
testcase_12 AC 135 ms
53,876 KB
testcase_13 AC 133 ms
54,164 KB
testcase_14 AC 133 ms
53,028 KB
testcase_15 AC 135 ms
53,020 KB
testcase_16 AC 137 ms
53,484 KB
testcase_17 AC 141 ms
53,044 KB
testcase_18 AC 158 ms
54,116 KB
testcase_19 AC 142 ms
53,208 KB
testcase_20 AC 258 ms
57,736 KB
testcase_21 AC 266 ms
57,920 KB
testcase_22 AC 272 ms
57,516 KB
testcase_23 AC 269 ms
57,616 KB
testcase_24 AC 270 ms
57,780 KB
testcase_25 AC 271 ms
57,728 KB
testcase_26 AC 271 ms
57,800 KB
testcase_27 AC 275 ms
57,808 KB
testcase_28 AC 275 ms
58,108 KB
testcase_29 AC 262 ms
57,200 KB
testcase_30 AC 274 ms
57,544 KB
testcase_31 AC 270 ms
57,852 KB
testcase_32 AC 261 ms
57,456 KB
testcase_33 AC 274 ms
57,956 KB
testcase_34 AC 275 ms
57,816 KB
testcase_35 AC 131 ms
53,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static interface Operation{
        public String toString();
        public static boolean get(long bitset, int index){
            return ((bitset>>index)&1L) != 0;
        }
        public static long set(long bitset, int index, boolean x){
            if(x) return bitset | (1L << index);
            else return bitset & ~(1L << index);
        }
        public long applyAsLong(long a);
    }
    static class Update implements Operation{
        int i;
        boolean x;
        public Update(int i, boolean x){
            this.i = i;
            this.x = x;
        }
        public long applyAsLong(long a){
            return Operation.set(a, i, x);
        }
        public String toString(){
            return String.format("UPD %d %d", i, x?1:0);
        }
    }
    static class And implements Operation{
        int i,j,k;
        public And(int i, int j, int k){
            this.i = i;
            this.j = j;
            this.k = k;
        }
        public long applyAsLong(long a){
            return Operation.set(a, i, Operation.get(a,j)&&Operation.get(a,k));
        }
        public String toString(){
            return String.format("AND %d %d %d", i,j,k);
        }
    }
    static class Xor implements Operation{
        int i,j,k;
        public Xor(int i, int j, int k){
            this.i = i;
            this.j = j;
            this.k = k;
        }
        public long applyAsLong(long a){
            return Operation.set(a, i, Operation.get(a,j)^Operation.get(a,k));
        }
        public String toString(){
            return String.format("XOR %d %d %d", i,j,k);
        }
    }
    
    public static void main(String[] args) throws Exception{
        final ContestScanner sc = new ContestScanner();
        final ContestPrinter pr = new ContestPrinter();
        
        final int N = sc.nextInt();
        final int K = sc.nextInt();
        final int T = sc.nextInt();
        boolean[] a = new boolean[N+1];

        List<Operation> ans = new ArrayList<>(10000);
        for(int i=0; i<N; i++){
            for(int j=i-1; j>=0; j--){
                ans.add(new And(N, j, j+1));
                ans.add(new Xor(j, j, j+1));
                ans.add(new Update(j+1, true));
                ans.add(new Xor(j, j, j+1));
                ans.add(new Xor(N, N, j+1));
                ans.add(new And(j, j, N));
                ans.add(new Xor(j, j, j+1));
                ans.add(new Xor(j+1, j+1, N));
            }
        }

        ans.add(new Update(N, true));
        ans.add(new And(N, N, K-1));


        pr.println(ans.size());
        for(Operation op: ans) pr.println(op);
        pr.close();
    }
}


class ContestScanner {
    private final java.io.InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private static final long LONG_MAX_TENTHS = 922337203685477580L;
    private static final int LONG_MAX_LAST_DIGIT = 7;
    private static final int LONG_MIN_LAST_DIGIT = 8;

    public ContestScanner(java.io.InputStream in){
        this.in = in;
    }
    public ContestScanner(){
        this(System.in);
    }
 
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (java.io.IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { 
        if (hasNextByte()) return buffer[ptr++]; else return -1;
    }
    private static 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 java.util.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 java.util.NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                int digit = b - '0';
                if (n >= LONG_MAX_TENTHS) {
                    if (n == LONG_MAX_TENTHS) {
                        if (minus) {
                            if (digit <= LONG_MIN_LAST_DIGIT) {
                                n = -n * 10 - digit;
                                b = readByte();
                                if (!isPrintableChar(b)) {
                                    return n;
                                } else if (b < '0' || '9' < b) {
                                    throw new NumberFormatException(
                                        String.format("%d%s... is not number", n, Character.toString(b))
                                    );
                                }
                            }
                        } else {
                            if (digit <= LONG_MAX_LAST_DIGIT) {
                                n = n * 10 + digit;
                                b = readByte();
                                if (!isPrintableChar(b)) {
                                    return n;
                                } else if (b < '0' || '9' < b) {
                                    throw new NumberFormatException(
                                        String.format("%d%s... is not number", n, Character.toString(b))
                                    );
                                }
                            }
                        }
                    }
                    throw new ArithmeticException(
                        String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit)
                    );
                }
                n = n * 10 + digit;
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
 
    public long[] nextLongArray(int length){
        long[] array = new long[length];
        for(int i=0; i<length; i++) array[i] = this.nextLong();
        return array;
    }
    public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map){
        long[] array = new long[length];
        for(int i=0; i<length; i++) array[i] = map.applyAsLong(this.nextLong());
        return array;
    }
    public int[] nextIntArray(int length){
        int[] array = new int[length];
        for(int i=0; i<length; i++) array[i] = this.nextInt();
        return array;
    }
    public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map){
        int[] array = new int[length];
        for(int i=0; i<length; i++) array[i] = map.applyAsInt(this.nextInt());
        return array;
    }
    public double[] nextDoubleArray(int length){
        double[] array = new double[length];
        for(int i=0; i<length; i++) array[i] = this.nextDouble();
        return array;
    }
    public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map){
        double[] array = new double[length];
        for(int i=0; i<length; i++) array[i] = map.applyAsDouble(this.nextDouble());
        return array;
    }
 
    public long[][] nextLongMatrix(int height, int width){
        long[][] mat = new long[height][width];
        for(int h=0; h<height; h++) for(int w=0; w<width; w++){
            mat[h][w] = this.nextLong();
        }
        return mat;
    }
    public int[][] nextIntMatrix(int height, int width){
        int[][] mat = new int[height][width];
        for(int h=0; h<height; h++) for(int w=0; w<width; w++){
            mat[h][w] = this.nextInt();
        }
        return mat;
    }
    public double[][] nextDoubleMatrix(int height, int width){
        double[][] mat = new double[height][width];
        for(int h=0; h<height; h++) for(int w=0; w<width; w++){
            mat[h][w] = this.nextDouble();
        }
        return mat;
    }
 
    public char[][] nextCharMatrix(int height, int width){
        char[][] mat = new char[height][width];
        for(int h=0; h<height; h++){
            String s = this.next();
            for(int w=0; w<width; w++){
                mat[h][w] = s.charAt(w);
            }
        }
        return mat;
    }
}

class ContestPrinter extends java.io.PrintWriter{
    public ContestPrinter(java.io.PrintStream stream){
        super(stream);
    }
    public ContestPrinter(){
        super(System.out);
    }
    
    private static String dtos(double x, int n) {
        StringBuilder sb = new StringBuilder();
        if(x < 0){
            sb.append('-');
            x = -x;
        }
        x += Math.pow(10, -n)/2;
        sb.append((long)x);
        sb.append(".");
        x -= (long)x;
        for(int i = 0;i < n;i++){
            x *= 10;
            sb.append((int)x);
            x -= (int)x;
        }
        return sb.toString();
    }

    @Override
    public void print(float f){
        super.print(dtos(f, 20));
    }
    @Override
    public void println(float f){
        super.println(dtos(f, 20));
    }
    @Override
    public void print(double d){
        super.print(dtos(d, 20));
    }
    @Override
    public void println(double d){
        super.println(dtos(d, 20));
    }
    
    

    public void printArray(int[] array, String separator){
        int n = array.length;
        if(n==0){
            super.println();
            return;
        }
        for(int i=0; i<n-1; i++){
            super.print(array[i]);
            super.print(separator);
        }
        super.println(array[n-1]);
    }
    public void printArray(int[] array){
        this.printArray(array, " ");
    }
    public void printArray(int[] array, String separator, java.util.function.IntUnaryOperator map){
        int n = array.length;
        if(n==0){
            super.println();
            return;
        }
        for(int i=0; i<n-1; i++){
            super.print(map.applyAsInt(array[i]));
            super.print(separator);
        }
        super.println(map.applyAsInt(array[n-1]));
    }
    public void printArray(int[] array, java.util.function.IntUnaryOperator map){
        this.printArray(array, " ", map);
    }

    public void printArray(long[] array, String separator){
        int n = array.length;
        if(n==0){
            super.println();
            return;
        }
        for(int i=0; i<n-1; i++){
            super.print(array[i]);
            super.print(separator);
        }
        super.println(array[n-1]);
    }
    public void printArray(long[] array){
        this.printArray(array, " ");
    }
    public void printArray(long[] array, String separator, java.util.function.LongUnaryOperator map){
        int n = array.length;
        if(n==0){
            super.println();
            return;
        }
        for(int i=0; i<n-1; i++){
            super.print(map.applyAsLong(array[i]));
            super.print(separator);
        }
        super.println(map.applyAsLong(array[n-1]));
    }
    public void printArray(long[] array, java.util.function.LongUnaryOperator map){
        this.printArray(array, " ", map);
    }    
}
0