結果

問題 No.1298 OR XOR
ユーザー yoshykaiyoshykai
提出日時 2020-11-27 21:35:39
言語 Java19
(openjdk 21)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 2,646 bytes
コンパイル時間 2,212 ms
コンパイル使用メモリ 75,096 KB
実行使用メモリ 53,564 KB
最終ジャッジ日時 2023-10-01 05:01:25
合計ジャッジ時間 4,001 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
52,240 KB
testcase_01 AC 41 ms
47,552 KB
testcase_02 AC 42 ms
49,412 KB
testcase_03 AC 43 ms
49,716 KB
testcase_04 AC 42 ms
49,772 KB
testcase_05 AC 41 ms
49,584 KB
testcase_06 AC 78 ms
53,420 KB
testcase_07 AC 80 ms
52,396 KB
testcase_08 AC 80 ms
50,492 KB
testcase_09 AC 79 ms
53,252 KB
testcase_10 AC 80 ms
53,564 KB
testcase_11 AC 79 ms
52,436 KB
testcase_12 AC 85 ms
52,196 KB
testcase_13 AC 84 ms
52,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
class Main{
  public static void main(String args[])throws IOException{
    int n = readI();
    int k=n,count=0;
    while(k>0){
      if(k%2==1){
        count++;
      }
      k=k>>1;
    }
    if(count==1){
      pl("-1 -1 -1");
    }else{
      int a=0,b=0,c=n;
      int i=0,t=0;
      count/=2;
      while(n>0){
        if(n%2==1){
          if(count>t){
            a=a|(1<<i);
            t++;
          }else{
            b=b|(1<<i);
            t++;
          }
        }
        i++;n/=2;
      }
      pl(a+" "+b+" "+c);
    }
  }

  static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
  public static String read(){
    try{
      return ctos((char)br.read());
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static char readC(){
    try{
      return (char)br.read();
    }catch(IOException e){
      e.printStackTrace();
      return (char)-1;
    }
  }
  public static String readL(){
    try{
      return br.readLine();
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static String readS(){
    StringBuilder sb = new StringBuilder();
    while(true){
      try{
        int k = br.read();
        if(k==-1||(char)k==' '||(char)k=='\n'){break;}
        sb.append((char)k);
      }catch(IOException e){
        e.printStackTrace();
      }
    }
    return sb.toString();
  }
  public static int readI(){
    return stoi(readS());
  }
  public static long readLong(){
    return stol(readS());
  }
  public static long stol(String s){
    return Long.parseLong(s);
  }
  public static String[] readSs(){
    return readL().split(" ");
  }
  public static int[] readIs(){
    return stoi(readSs());
  }
  public static int stoi(String s){
    return Integer.parseInt(s);
  }
  public static int[] stoi(String s[]){
    int a[]=new int[s.length];
    for(int i=0;i<s.length;i++){
      a[i]=stoi(s[i]);
    }
    return a;
  }
  public static String itos(int i){
    return String.valueOf(i);
  }
  public static String[] itos(int[] a){
    String s[]=new String[a.length];
    for(int i=0;i<a.length;i++){
      s[i]=itos(a[i]);
    }
    return s;
  }
  public static String ctos(char c){
    return String.valueOf(c);
  }
  public static String cstos(char[] c){
    return new String(c);
  }
  public static char stoc(String s){
    return s.charAt(0);
  }
  public static char[] stocs(String s){
    return s.toCharArray();
  }
}
0