結果

問題 No.483 マッチ並べ
ユーザー kuuso1
提出日時 2017-02-10 23:57:46
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 2,046 bytes
コンパイル時間 1,087 ms
コンパイル使用メモリ 116,396 KB
実行使用メモリ 18,932 KB
最終ジャッジ日時 2024-12-29 11:23:54
合計ジャッジ時間 4,517 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 53
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #
プレゼンテーションモードにする

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}
class Sol{
public void Solve(){
int H = 120;
int W = 120;
int HW = H*W;
List<int>[] E = new List<int>[HW];
for(int i=0;i<HW;i++) E[i] = new List<int>();
Func<int,int,int> enc = (r,c) => r*W+c;
var deg = new Dictionary<int,int>();
for(int i=0;i<N;i++){
int v = enc(R0[i],C0[i]);
int w = enc(R1[i],C1[i]);
E[v].Add(w);
E[w].Add(v);
if(!deg.ContainsKey(v))deg.Add(v,0);deg[v]++;
if(!deg.ContainsKey(w))deg.Add(w,0);deg[w]++;
}
bool[] used = new bool[HW];
foreach(var v in deg.Keys){
if(used[v]) continue;
int nc = 0;
int ne = 0;
Queue<int> Q = new Queue<int>();
used[v] = true;
Q.Enqueue(v);
while(Q.Count>0){
var now = Q.Dequeue();
nc++;
ne += E[now].Count;
foreach(var nxt in E[now]){
if(!used[nxt]){
used[nxt] = true;
Q.Enqueue(nxt);
}
}
}
ne /= 2;
if(nc >= ne) continue;
Console.WriteLine("NO");
return;
}
Console.WriteLine("YES");
}
int N;
int[] R0,C0,R1,C1;
public Sol(){
N = ri();
R0 = new int[N];
R1 = new int[N];
C0 = new int[N];
C1 = new int[N];
for(int i=0;i<N;i++){
var d = ria();
R0[i] = d[0];
C0[i] = d[1];
R1[i] = d[2];
C1[i] = d[3];
}
}
static String rs(){return Console.ReadLine();}
static int ri(){return int.Parse(Console.ReadLine());}
static long rl(){return long.Parse(Console.ReadLine());}
static double rd(){return double.Parse(Console.ReadLine());}
static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0