結果

問題 No.274 The Wall
ユーザー PulmnPulmn
提出日時 2018-07-19 18:33:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 514 ms / 2,000 ms
コード長 1,968 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 157,892 KB
実行使用メモリ 134,516 KB
最終ジャッジ日時 2023-09-04 02:33:06
合計ジャッジ時間 3,611 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 177 ms
70,712 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 514 ms
134,516 KB
testcase_12 AC 24 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 77 ms
28,888 KB
testcase_17 AC 75 ms
28,648 KB
testcase_18 AC 80 ms
29,480 KB
testcase_19 AC 20 ms
4,376 KB
testcase_20 AC 23 ms
4,376 KB
testcase_21 AC 23 ms
4,380 KB
testcase_22 AC 25 ms
4,380 KB
testcase_23 AC 26 ms
4,380 KB
testcase_24 AC 25 ms
4,376 KB
testcase_25 AC 25 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ull mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Graph{
	private:
	int n,N;
	vvi g,rg;
	vi scc,used;
	stack<int> stc;
	void Order(int v){
		used[v]=1;
		for(auto u:g[v]) if(!used[u]) Order(u);
		stc.push(v);
	}
	void DFS(int v,int t){
		used[v]=1;
		for(auto u:rg[v]) if(!used[u]) DFS(u,t);
		scc[v]=t;
	}
	int SCC(){
		scc=used=vi(n);
		rg=vvi(n);
		for(int i=0;i<n;i++){
			if(!used[i]) Order(i);
			for(auto v:g[i]) rg[v].push_back(i);
		}
		int t=0;
		used=vi(n);
		while(!stc.empty()){
			int v=stc.top();
			stc.pop();
			if(!used[v]) DFS(v,t++);
		}
		return t;
	}
	public:
	Graph(int v){
		n=v;
		N=n/2;
		g=vvi(v);
	}
	void add_edge(int s,int t){
		g[s].push_back(t);
	}
	void Add(int u,int v){
		add_edge((u+N)%n,v);
		add_edge((v+N)%n,u);
	}
	void solve(){
		SCC();
		bool B=1;
		for(int i=0;i<N;i++) if(scc[i]==scc[i+N]) B=0;
		cout<<(B?"YES":"NO")<<endl;
	}
};

int n,m;
vi a,b;

int f(int A,int B){
	if(B) A=m-A-1;
	return A;
}

int main(){
	cin>>n>>m;
	Graph g(4*n);
	a=b=vi(n);
	for(int i=0;i<n;i++) cin>>a[i]>>b[i];
	for(int i=0;i<n;i++){
		g.Add(i,i+n);
		g.Add(i+2*n,i+3*n);
	}
	for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) for(int k=0;k<4;k++){
		int I=k/2,J=k%2,l=f(a[i],I),r=f(b[i],I),L=f(a[j],J),R=f(b[j],J);
		if(I) swap(l,r);
		if(J) swap(L,R);
		if(max(l,L)<=min(r,R)) g.Add(i+2*I*n,j+2*J*n);
	}
	g.solve();
}
0