結果

問題 No.483 マッチ並べ
ユーザー rapurasurapurasu
提出日時 2017-02-16 00:40:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 2,328 bytes
コンパイル時間 1,235 ms
コンパイル使用メモリ 150,968 KB
実行使用メモリ 7,032 KB
最終ジャッジ日時 2023-08-28 17:36:55
合計ジャッジ時間 3,354 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,924 KB
testcase_01 AC 6 ms
6,848 KB
testcase_02 AC 5 ms
6,752 KB
testcase_03 AC 6 ms
6,816 KB
testcase_04 AC 6 ms
6,752 KB
testcase_05 AC 5 ms
6,788 KB
testcase_06 AC 5 ms
6,752 KB
testcase_07 AC 5 ms
6,808 KB
testcase_08 AC 6 ms
6,816 KB
testcase_09 AC 5 ms
6,788 KB
testcase_10 AC 5 ms
6,784 KB
testcase_11 AC 5 ms
6,812 KB
testcase_12 AC 5 ms
6,872 KB
testcase_13 AC 5 ms
6,784 KB
testcase_14 AC 5 ms
6,800 KB
testcase_15 AC 5 ms
7,020 KB
testcase_16 AC 6 ms
6,908 KB
testcase_17 AC 6 ms
7,032 KB
testcase_18 AC 5 ms
6,876 KB
testcase_19 AC 5 ms
6,752 KB
testcase_20 AC 5 ms
6,880 KB
testcase_21 AC 5 ms
6,792 KB
testcase_22 AC 5 ms
7,024 KB
testcase_23 AC 5 ms
6,800 KB
testcase_24 AC 5 ms
6,764 KB
testcase_25 AC 5 ms
6,828 KB
testcase_26 AC 5 ms
6,812 KB
testcase_27 AC 5 ms
6,768 KB
testcase_28 AC 6 ms
6,892 KB
testcase_29 AC 6 ms
6,808 KB
testcase_30 AC 5 ms
6,768 KB
testcase_31 AC 5 ms
6,772 KB
testcase_32 AC 5 ms
6,772 KB
testcase_33 AC 5 ms
6,884 KB
testcase_34 AC 5 ms
6,804 KB
testcase_35 AC 5 ms
6,884 KB
testcase_36 AC 5 ms
6,936 KB
testcase_37 AC 6 ms
6,888 KB
testcase_38 AC 6 ms
6,812 KB
testcase_39 AC 5 ms
6,884 KB
testcase_40 AC 5 ms
6,796 KB
testcase_41 AC 5 ms
6,884 KB
testcase_42 AC 6 ms
6,916 KB
testcase_43 AC 5 ms
6,864 KB
testcase_44 AC 5 ms
6,828 KB
testcase_45 AC 5 ms
6,812 KB
testcase_46 AC 5 ms
6,884 KB
testcase_47 AC 5 ms
6,764 KB
testcase_48 AC 5 ms
7,024 KB
testcase_49 AC 5 ms
6,852 KB
testcase_50 AC 5 ms
6,804 KB
testcase_51 AC 5 ms
6,832 KB
testcase_52 AC 5 ms
6,824 KB
testcase_53 AC 5 ms
6,868 KB
testcase_54 AC 6 ms
6,936 KB
testcase_55 AC 5 ms
6,800 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void add_edge(int, int, int)’:
main.cpp:19:48: warning: narrowing conversion of ‘G[to].std::vector<edge>::size()’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ inside { } [-Wnarrowing]
      G[from].push_back((edge){to,cap,G[to].size()});
                                      ~~~~~~~~~~^~
main.cpp:20:50: warning: narrowing conversion of ‘(G[from].std::vector<edge>::size() - 1)’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ inside { } [-Wnarrowing]
      G[to].push_back((edge){from,0,G[from].size()-1});
                                    ~~~~~~~~~~~~~~^~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define MAX_V 100000
#define INF 10000000

//辺を表す構造体(行き先,容量,逆元)
struct edge{int to,cap,rev;};

vector<edge>G[MAX_V];
int level[MAX_V];//sからの距離
int iter[MAX_V];//どこまで調べたか

//fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from,int to,int cap){
     G[from].push_back((edge){to,cap,G[to].size()});
     G[to].push_back((edge){from,0,G[from].size()-1});
}
//sからの最短距離をBFSで計算する
void bfs(int s){
   memset(level,-1,sizeof(level));
   queue<int>que;
   level[s]=0;
   que.push(s);
   while(!que.empty()){
      int v=que.front();que.pop();
      REP(i,G[v].size()){
          edge &e=G[v][i];
          if(e.cap>0&&level[e.to]<0){
             level[e.to] =level[v]+1;
             que.push(e.to);
          }
      }
   }
}

//増加パスをdfsで探す
int dfs(int v,int t,int f){
   if(v==t)return f;
   for(int &i=iter[v];i<G[v].size();i++){
       edge &e =G[v][i];
       if(e.cap >0 && level[v]<level[e.to]){
          int d=dfs(e.to,t,min(f,e.cap));
          if(d>0){
             e.cap-=d;
             G[e.to][e.rev].cap+=d;
             return d;
          }
       }
   }
   return 0;
}

//sからtへの最大流を求める
int max_flow(int s,int t){
    int flow=0;
    for(;;){
        bfs(s);
        if(level[t] <0)return flow;
        memset(iter,0,sizeof(iter));
        int f;
        while((f=dfs(s,t,INF))>0){
           flow+=f;
        }
    }
    return flow;
}

int main(){
        REP(i,111){
            REP(j,111){
                add_edge(i*111+j,111*111,1);
            }
        }
        int N;
        cin>>N;
        int st=111*111+N+1;
        for(int i=1;i<=N;i++){
            int now=111*111+i;
            add_edge(st,now,1);
            int a,b,c,d;
            cin>>a>>b>>c>>d;
            add_edge(now,a*111+b,1);
            add_edge(now,c*111+d,1);
        }
        int ans=max_flow(st,111*111);
        //cout<<ans<<endl;
        if(ans==N){
           cout<<"YES"<<endl;
        }else{
           cout<<"NO"<<endl;
        }
	return(0);
}
0