結果

問題 No.360 増加門松列
ユーザー threepipes_sthreepipes_s
提出日時 2016-04-17 22:47:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 4,545 bytes
コンパイル時間 2,238 ms
コンパイル使用メモリ 93,460 KB
実行使用メモリ 51,288 KB
最終ジャッジ日時 2024-06-06 12:42:19
合計ジャッジ時間 4,359 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
50,876 KB
testcase_01 AC 75 ms
51,016 KB
testcase_02 AC 49 ms
50,000 KB
testcase_03 AC 47 ms
50,092 KB
testcase_04 AC 71 ms
51,084 KB
testcase_05 AC 72 ms
50,868 KB
testcase_06 AC 71 ms
51,076 KB
testcase_07 AC 74 ms
50,952 KB
testcase_08 AC 72 ms
51,232 KB
testcase_09 AC 72 ms
50,908 KB
testcase_10 AC 52 ms
50,128 KB
testcase_11 AC 47 ms
50,376 KB
testcase_12 AC 72 ms
50,956 KB
testcase_13 AC 52 ms
50,312 KB
testcase_14 AC 50 ms
50,264 KB
testcase_15 AC 63 ms
50,908 KB
testcase_16 AC 47 ms
50,004 KB
testcase_17 AC 50 ms
50,380 KB
testcase_18 AC 72 ms
50,776 KB
testcase_19 AC 74 ms
51,288 KB
testcase_20 AC 75 ms
50,800 KB
testcase_21 AC 72 ms
50,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.BitSet;
import java.util.HashMap;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
	IOException {Main solve = new Main();solve.solve();}
	void dump(int[]a){for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");System.out.println();}
	void dump(int[]a,int n){for(int i=0;i<a.length;i++)System.out.printf("%"+n+"d",a[i]);System.out.println();}
	void dump(long[]a){for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");System.out.println();}
	void dump(char[]a){for(int i=0;i<a.length;i++)System.out.print(a[i]);System.out.println();}
	long pow(long a,int n){long r=1;while(n>0){if((n&1)==1)r*=a;a*=a;n>>=1;}return r;}
	String itob(int a,int l){return String.format("%"+l+"s",Integer.toBinaryString(a)).replace(' ','0');}
	int binarySearchSmallerMax(int[]a,int v) // get maximum index which a[idx]<=v
	{int l=0,r=a.length-1,s=0;while(l<=r){int m=(l+r)/2;if(a[m]>v)r=m-1;else{l=m+1;s=m;}}return a[s]>v?-1:s;}
	void solve() throws NumberFormatException, IOException{
		final ContestScanner in = new ContestScanner();
		Writer out = new Writer();
		int[] a = new int[7];
		for(int i=0; i<7; i++) a[i] = in.nextInt();
		Permutation p = new Permutation(7, 7);
		int[] k = new int[7];
		out:while(p.next()){
			for(int i=0; i<7; i++){
				k[i] = a[p.p[i]];
			}
			for(int i=0; i<=4; i++){
				if(!isKPlus(k[i], k[i+1], k[i+2])) continue out;
			}
			System.out.println("YES");
			return;
		}
		System.out.println("NO");
	}
	
	boolean isKPlus(int a0, int a1, int a2){
		return a0<a2 && (a1>a0 && a1>a2 || a1<a0 && a1<a2);
	}
	boolean isK(int a0, int a1, int a2){
		return a0!=a2 && (a1>a0 && a1>a2 || a1<a0 && a1<a2);
	}
}

class Permutation{
	// max=10
	// n=10: 160ms
	// n=11: 1600-1700ms
	int n;
	int max;
	BitSet used;
	int[] p;
	public Permutation(int n, int max){
		this.n = n;
		this.max = max;
		used = new BitSet(n);
		p = new int[n];
	}
	
	public boolean next(){
		if(used.cardinality() == 0){
			for(int i=0; i<n; i++){
				p[i] = i;
			}
			used.set(0, n);
			return true;
		}
		int i;
		for(i=n-1; i>=0; i--){
			used.clear(p[i]);
			if((used.nextClearBit(p[i]+1)) < max) break;
		}
		if(i<0) return false;
		p[i] = used.nextClearBit(p[i]+1);
		used.set(p[i]);
		int idx = i+1;
		for(i=used.nextClearBit(0); i<max && idx<n; i=used.nextClearBit(i+1)){
			p[idx++] = i;
			used.set(i);
		}
		return true;
	}
	
	public String toString(){
		StringBuilder sb = new StringBuilder();
		for(int i=0; i<n; i++){
			sb.append(p[i]+" ");
		}
		return sb.toString();
	}
}

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);}
}
class Timer{
	long time;
	public void set(){time=System.currentTimeMillis();}
	public long stop(){return time=System.currentTimeMillis()-time;}
	public void print()
	{System.out.println("Time: "+(System.currentTimeMillis()-time)+"ms");}
	@Override public String toString(){return"Time: "+time+"ms";}
}
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 {
	private InputStreamReader in;private int c=-2;
	public ContestScanner()throws IOException 
	{in=new InputStreamReader(System.in);}
	public ContestScanner(String filename)throws IOException
	{in=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());}
}
0