結果

問題 No.1144 Triangles
ユーザー 37zigen37zigen
提出日時 2020-08-04 13:01:28
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 3,605 bytes
コンパイル時間 2,202 ms
コンパイル使用メモリ 76,580 KB
実行使用メモリ 62,176 KB
最終ジャッジ日時 2023-10-12 14:59:07
合計ジャッジ時間 8,233 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,808 KB
testcase_01 AC 42 ms
49,440 KB
testcase_02 AC 43 ms
49,516 KB
testcase_03 AC 43 ms
49,492 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.awt.geom.Line2D;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) {
		new Main().run();
	}
	
	double f(double theta) {
		return theta>=0?theta:(2*Math.PI+theta);
	}
	
	final long MOD=(long)1e9+7;

	long pow(long a,long n) {
		return n!=0?pow(a*a%MOD,n/2)*(n%2==1?a:1)%MOD:1;
	}
	
	long inv(long a) {
		return pow(a,MOD-2);
	}
	
	long ADD(long a,long b) {
		long ret=a+b;
		return ret<MOD?ret:ret-MOD;
	}
	
	
	void run() {
		FastScanner sc = new FastScanner();
		int n=sc.nextInt();
		long[][] a=new long[n][2];
		for (int i=0;i<n;++i) {
			a[i][0]=sc.nextLong();
			a[i][1]=sc.nextLong();
		}
		long ans=0;
		for (int i=0;i<n;++i) {
			long[][] p=new long[n-1][2];
			{
				int pointer=0;
				for (int j=0;j<n;++j) {
					if (i==j) continue;
					p[pointer][0]=a[j][0]-a[i][0];
					p[pointer][1]=a[j][1]-a[i][1];
					++pointer;
				}
			}
			Arrays.sort(p,new Comparator<long[]>() {
				@Override
				public int compare(long[] o1, long[] o2) {
					return Double.compare(f(Math.atan2(o1[1], o1[0])), f(Math.atan2(o2[1], o2[0])));
				}
			});
			
			long[] sumx=new long[2*p.length+1];
			long[] sumy=new long[2*p.length+1];
			
			for (int j=1;j<=2*p.length;++j) {
				sumx[j]=ADD(p[(j-1)%(n-1)][0],sumx[j-1]);
				sumy[j]=ADD(p[(j-1)%(n-1)][1],sumy[j-1]);
			}
			int t=0;
			for (int j=0;j<n-1;++j) {
				t=Math.max(t, j+1);
				long x0=p[j][0];
				long y0=p[j][1];
				while (t<2*(n-1) && Line2D.relativeCCW(0, 0, p[j][0], p[j][1], p[t%(n-1)][0], p[t%(n-1)][1])==-1) {
					++t;
				}
				long dsx=sumx[t]-sumx[j+1];
				long dsy=sumy[t]-sumy[j+1];
				long add=x0*dsy%MOD+(MOD-y0*dsx%MOD);
				ans=ADD(ans,add);
			}
		}
		System.out.println(ans*inv(3)%MOD);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	class FastScanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			return (int) nextLong();
		}
	}
}
0