Submission #832324

# Submission time Handle Problem Language Result Execution time Memory
832324 2023-08-21T09:00:04 Z vjudge1 Ice Hockey World Championship (CEOI15_bobek) Java 11
Compilation error
0 ms 0 KB

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.StreamTokenizer;
import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;

public class Main {
	
	
     static long m;
     static int N=50,n;
     static Vector<Long> a=new Vector<>();
     static Vector<Long> b=new Vector<>();
     static long init[]=new long[N];
     static BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
     public static void main(String[] args)throws IOException {
    	 StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    	 in.nextToken();
    	 n=(int)in.nval;
    	 in.ordinaryChars('0', '9');
    	 in.wordChars('0', '9');
    	 in.nextToken();
    	 m=Long.parseLong(in.sval);
		
		for (int i = 1; i <=n; i++) {
			 in.nextToken();
	    	 init[i]=Long.parseLong(in.sval);
		}
		int mid=n/2;
		dfs(1,mid,0,a);
		dfs(mid+1,n,0,b);
	
		
		Collections.sort(a,new Comparator<Long>() {
			public int compare(Long o1, Long o2) {
				if(o1<o2)return -1;
				else if(o1==o2)return 0;
				else return 1;
			}
		});

		//排序
		long sum=0;
		for (int i = 0; i <b.size(); i++) {
			sum+=br(m-b.get(i));
		}
		
		out.write(sum+"\n");
		out.flush();
		
		
	}
     
     static long br(long x) {
    	  int l=0,r=a.size()-1;
    	  while(l<r) {
    		  int mid=(l+r+1)/2;
    		  if(a.get(mid)<=x)l=mid;
    		  else r=mid-1;
    	  }
    	  //判断无解的情况
    	  return l+1;
     }
     
     static void dfs(int l,int r,long sum,Vector<Long>c) {
    	 
    	 if(sum>m)return;
    	 if(l>r) { 
    		 c.add(sum);
    		 return;
    	 }
    	 dfs(l+1,r,sum+init[l],c);
    	 dfs(l+1,r,sum,c);
    	 
     }
	
	
	
}

Compilation message

bobek.java:13: error: class Main is public, should be declared in a file named Main.java
public class Main {
       ^
1 error