結果

問題 No.635 自然門松列
コンテスト
ユーザー fura
提出日時 2020-10-19 03:31:46
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 2 ms / 650 ms
コード長 777 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,897 ms
コンパイル使用メモリ 201,428 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-29 09:18:52
合計ジャッジ時間 2,825 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         rep(i,3) scanf("%d",&x[i]);
      |                  ~~~~~^~~~~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         rep(i,3) scanf("%d",&v[i]);
      |                  ~~~~~^~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:39:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         int q; scanf("%d",&q); rep(_,q) solve();
      |                ~~~~~^~~~~~~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const double EPS=1e-8;

void solve(){
	int x[3],v[3];
	rep(i,3) scanf("%d",&x[i]);
	rep(i,3) scanf("%d",&v[i]);

	vector<double> T={0,1e9};
	rep(i,3) rep(j,3) if(i!=j) {
		if(x[i]<x[j] && v[i]>v[j]){
			// x_i+v_i*t = x_j+v_j*t <=> t = (x_j-x_i)/(v_i-v_j)
			T.emplace_back(double(x[j]-x[i])/(v[i]-v[j]));
		}
	}

	sort(T.begin(),T.end());

	rep(i,T.size()-1){
		double t=(T[i]+T[i+1])/2;
		double a[3];
		rep(j,3) a[j]=x[j]+v[j]*t;
		if(abs(a[0]-a[1])>EPS && abs(a[1]-a[2])>EPS && abs(a[0]-a[2])>EPS){
			if((a[0]>a[1] && a[1]<a[2]) || (a[0]<a[1] && a[1]>a[2])){
				puts("YES");
				return;
			}
		}
	}
	puts("NO");
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}
0