第6回日本情報オリンピック 予選(過去問)から、その提出コードの解答例です。
AtCoderとは、コンテストを通じて、プログラミングやアルゴリズムを学習するサービスです。
atcoder.jp
プログラミングコンテストとは、「与えられた問題をいかに素早く、正確に」解くことができるかを競うものです。
「競技プログラミング」を略して、「競プロ」などと呼ばれています。
#E - 品質検査
僕が作成、提出したコードは、以下のとおりです。
/* AtCoder Problems in C++ #E - 品質検査 https://atcoder.jp/contests/joi2007yo/tasks/joi2007yo_e 提出コードの解答例 https://neguse-atama.hatenablog.com */ #include<bits/stdc++.h> using namespace std; using ll=long long; int main(void){ ll a,b,c,n; cin>>a>>b>>c>>n; vector<ll> ans(a+b+c+1,2); vector<ll> i(n),j(n),k(n),l(n); for(ll x=0;x<n;x++){ cin>>i[x]>>j[x]>>k[x]>>l[x]; if(l[x]==1){ ans[i[x]]=1; ans[j[x]]=1; ans[k[x]]=1; } } for(ll x=0;x<n;x++){ if(ans[i[x]]==1 && ans[j[x]]==1 && ans[k[x]]!=1){ ans[k[x]]=0; } if(ans[i[x]]==1 && ans[j[x]]!=1 && ans[k[x]]==1){ ans[j[x]]=0; } if(ans[i[x]]!=1 && ans[j[x]]==1 && ans[k[x]]==1){ ans[i[x]]=0; } } for(ll x=1;x<=a+b+c;x++){ cout<<ans[x]<<endl; } return 0; }