結果

問題 No.792 真理関数をつくろう
ユーザー threepipes_sthreepipes_s
提出日時 2019-02-22 21:42:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 697 ms / 2,000 ms
コード長 3,865 bytes
コンパイル時間 2,258 ms
コンパイル使用メモリ 87,936 KB
実行使用メモリ 68,988 KB
最終ジャッジ日時 2024-11-25 08:14:49
合計ジャッジ時間 7,504 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,756 KB
testcase_01 AC 177 ms
56,932 KB
testcase_02 AC 118 ms
53,928 KB
testcase_03 AC 233 ms
61,096 KB
testcase_04 AC 111 ms
53,320 KB
testcase_05 AC 227 ms
58,952 KB
testcase_06 AC 397 ms
59,752 KB
testcase_07 AC 146 ms
56,144 KB
testcase_08 AC 112 ms
53,452 KB
testcase_09 AC 122 ms
54,264 KB
testcase_10 AC 127 ms
53,836 KB
testcase_11 AC 120 ms
53,656 KB
testcase_12 AC 119 ms
55,708 KB
testcase_13 AC 118 ms
53,988 KB
testcase_14 AC 117 ms
53,704 KB
testcase_15 AC 149 ms
53,864 KB
testcase_16 AC 255 ms
59,428 KB
testcase_17 AC 137 ms
53,876 KB
testcase_18 AC 126 ms
53,692 KB
testcase_19 AC 122 ms
55,840 KB
testcase_20 AC 191 ms
57,860 KB
testcase_21 AC 697 ms
68,988 KB
testcase_22 AC 116 ms
53,824 KB
testcase_23 AC 54 ms
50,912 KB
testcase_24 AC 111 ms
55,532 KB
testcase_25 AC 118 ms
53,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;

public class Main implements Runnable {
    static ContestScanner in;
    static Writer out;
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
    }

    public void run() {
        Main main = new Main();
        try {
            in = new ContestScanner();
            out = new Writer();
            main.solve();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        int n = in.nextInt();
        int h = 1<<n;
        int[][] q = new int[1<<n][n];
        int[] r = new int[h];
        int r1 = 0;
        int r0 = 1;
        String s = "";
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < n; j++) {
                q[i][j] = in.nextInt();
            }
            r[i] = in.nextInt();
            r0 *= r[i];
            r1 += r[i];
            if (r[i] == 0) {
                continue;
            }
            String t = "";
            for (int j = 0; j < n; j++) {
                if (j > 0) t += "∧";
                t += (q[i][j] == 0 ? "¬" : "") + "P_" + (j + 1);
            }
            if (s.length() > 0) {
                s += "∨";
            }
            s += "(" + t + ")";
        }

        if (r0 == 1) { // all 1
            System.out.println("A=⊤");
            return;
        }
        if (r1 == 0) { // all 0
            System.out.println("A=⊥");
            return;
        }
        System.out.println("A=" + s);
    }
}


@SuppressWarnings("serial")
class MultiSet<T> extends HashMap<T, Integer>{
    @Override public Integer get(Object key){return containsKey(key)?super.get(key):0;}
    public void add(T key,int v){put(key,get(key)+v);}
    public void add(T key){put(key,get(key)+1);}
    public void sub(T key){final int v=get(key);if(v==1)remove(key);else put(key,v-1);}
    public MultiSet<T> merge(MultiSet<T> set)
    {MultiSet<T>s,l;if(this.size()<set.size()){s=this;l=set;}else{s=set;l=this;}
        for(Entry<T,Integer>e:s.entrySet())l.add(e.getKey(),e.getValue());return l;}
}

class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException{super(System.out);}
}
class ContestScanner implements Closeable{
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}
0