답안 #442017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442017 2021-07-06T18:20:52 Z RGBB A Game with Grundy (CCO20_day1problem1) Java 11
컴파일 오류
0 ms 0 KB
import java.util.*;
import java.io.*;
public class CCOq1
{
	public static void main(String[] args)
	{
		FastReader sc=new FastReader();
		int n=sc.nextInt();
		int l=sc.nextInt();
		int r=sc.nextInt();
		int y=sc.nextInt();
		LinkedList<Integer>poslist=new LinkedList<Integer>();
		LinkedList<Integer>neglist=new LinkedList<Integer>();
		int initial=0;
		for(int i=0;i<n;i++)
		{
			int x=sc.nextInt();
			int v=sc.nextInt();
			int h=sc.nextInt();
			int amount=(h*y)/v;
			if((double)(h*y)/(double)v%1==0)
			{
				amount--;
			}
//			System.out.println(amount);
			if(x-l-amount>0)
			{
				poslist.add(x-l-amount);
			}
			else
			{
				initial++;
			}
			if(x-l+amount+1<r-l+1)
			{
				neglist.add(x-l+amount+1);
			}
		}
		Collections.sort(poslist);
		Collections.sort(neglist);
//		for(int i=0;i<r-l+1;i++)
//		{
//			System.out.print(array[i]+" ");
//		}
//		System.out.println();
		
//		System.out.println(poslist);
//		System.out.println(neglist);
		poslist.add(r-l+1);
		int[]num=new int[n+1];
		int pos=0;
		int f=poslist.size()+neglist.size();
		for(int i=0;i<f;i++)
		{
//			System.out.println(initial);
			int amount=0;
			if(neglist.isEmpty())
			{
				amount=poslist.poll();
				if(initial<=n)
				{
					num[initial]+=amount-pos;
				}
				initial++;
				pos=amount;
			}
			else if(poslist.isEmpty())
			{
				amount=neglist.poll();
				if(initial<=n)
				{
					num[initial]+=amount-pos;
				}
				initial--;
				pos=amount;
			}
			else
			{
				if(poslist.peek()<neglist.peek())
				{
					amount=poslist.poll();
					if(initial<=n)
					{
						num[initial]+=amount-pos;
					}
					initial++;
					pos=amount;
				}
				else
				{
					amount=neglist.poll();
					if(initial<=n)
					{
						num[initial]+=amount-pos;
					}
					initial--;
					pos=amount;
				}
			}
		}
		
//		for(int i=0;i<n+1;i++)
//		{
//			System.out.print(num[i]+" ");
//		}
//		System.out.println();
		
		for(int i=1;i<n+1;i++)
		{
			num[i]+=num[i-1];
		}
		for(int i=0;i<n+1;i++)
		{
			System.out.println(num[i]);
		}
	}
	public static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;
		public FastReader()
		{
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		String next()
		{
			while(st==null||!st.hasMoreElements())
			{
				try
				{
					st=new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt()
		{
			return Integer.parseInt(next());
		}
		long nextLong()
		{
			return Long.parseLong(next());
		}
		double nextDouble()
		{
			return Double.parseDouble(next());
		}
		String nextLine()
		{
			String str=null;
			try
			{
				str=br.readLine();
			}
			catch(IOException e) 
			{
				e.printStackTrace();
			}
			return str;
		}
	}
}

Compilation message

Main.java:3: error: class CCOq1 is public, should be declared in a file named CCOq1.java
public class CCOq1
       ^
1 error