結果
| 問題 | No.1123 Afforestation |
| コンテスト | |
| ユーザー |
snuke
|
| 提出日時 | 2020-07-22 23:38:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 7,628 bytes |
| 記録 | |
| コンパイル時間 | 2,228 ms |
| コンパイル使用メモリ | 199,844 KB |
| 最終ジャッジ日時 | 2025-01-12 03:57:35 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In instantiation of ‘std::istream& operator>>(std::istream&, std::vector<_Tp>&) [with T = std::pair<int, int>; std::istream = std::basic_istream<char>]’:
main.cpp:138:17: required from here
main.cpp:39:15: error: no match for ‘operator>>’ (operand types are ‘std::istream’ {aka ‘std::basic_istream<char>’} and ‘__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type’ {aka ‘std::pair<int, int>’})
39 | {rep(j,sz(v))i>>v[j];return i;}
| ~^~~~
In file included from /usr/include/c++/13/sstream:40,
from /usr/include/c++/13/complex:45,
from /usr/include/c++/13/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127,
from main.cpp:1:
/usr/include/c++/13/istream:325:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’
325 | operator>>(void*& __p)
| ^~~~~~~~
/usr/include/c++/13/istream:325:25: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type’ {aka ‘std::pair<int, int>’} to ‘void*&’
325 | operator>>(void*& __p)
| ~~~~~~~^~~
/usr/include/c++/13/istream:224:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’
224 | operator>>(long double& __f)
| ^~~~~~~~
/usr/include/c++/13/istream:224:31: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type’ {aka ‘std::pair<int, i
ソースコード
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts(":("); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
typedef v(string) vs;
// Max flow
// !! Be care of double and INF !!
struct Maxflow {
typedef int TT;
int n;
vi to, next, head, dist, it;
vector<TT> lim;
Maxflow(){}
Maxflow(int n):n(n),head(n,-1),it(n){}
void add(int a, int b, TT c=1) {
next.pb(head[a]); head[a] = sz(to); to.pb(b); lim.pb(c);
next.pb(head[b]); head[b] = sz(to); to.pb(a); lim.pb(0);
}
void bfs(int sv) {
dist = vi(n,INF);
queue<int> q;
dist[sv] = 0; q.push(sv);
while (!q.empty()){
int v = q.front(); q.pop();
for (int i = head[v]; i != -1; i = next[i]) {
if (lim[i] && dist[to[i]] == INF) { // double !!
dist[to[i]] = dist[v]+1; q.push(to[i]);
}
}
}
}
TT dfs(int v, int tv, TT nf=INF) { // INF !!
if (v == tv) return nf;
for (; it[v] != -1; it[v] = next[it[v]]) {
int u = to[it[v]]; TT f;
if (!lim[it[v]] || dist[v] >= dist[u]) continue; // double !!
if (f = dfs(u, tv, min(nf, lim[it[v]])), f) { // double !!
lim[it[v]] -= f;
lim[it[v]^1] += f;
return f;
}
}
return 0;
}
TT solve(int sv, int tv) {
TT flow = 0, f;
while (1) {
bfs(sv);
if (dist[tv] == INF) return flow;
rep(i,n) it[i] = head[i];
while (f = dfs(sv,tv), f) flow += f;
}
}
};
//
// coordinate compression
struct X {
typedef int T;
vector<T> d;
X() {}
// X(vector<T>& a): d(a) {
// init();
// for (T& na : a) na = (*this)(na);
// }
void add(const T& x) { d.pb(x);}
void init() {
sort(rng(d));
d.erase(unique(rng(d)), d.end());
}
int size() const { return sz(d);}
T operator[](int i) const { return d[i];}
int operator()(const T& x) const { return upper_bound(rng(d),x)-d.begin()-1;}
bool in(const T& x) const { return binary_search(rng(d), x);}
};
//
int main() {
int h,w;
scanf("%d%d",&h,&w);
vi a(h), b(w);
cin>>a>>b;
int n;
scanf("%d",&n);
vp p(n); cin>>p;
rep(i,n) p[i].fi--;
rep(i,n) p[i].se--;
// X xs, ys;
// rep(i,n) xs.add(p[i].fi);
// rep(i,n) ys.add(p[i].se);
// xs.init();
// ys.init();
// int eh = sz(xs), dh = h-eh;
// int ew = sz(ys), dw = w-ew;
vs ans(h,string(w,'.'));
rep(i,n) ans[p[i].fi][p[i].se] = 'x';
// int sv = h+w, tv = sv+1;
// Maxflow g(tv+1);
// rep(ei,eh) {
// int i = xs[ei];
// rep(j,w) {
// if (ys.in(j)) continue;
// g.add(i,h+j);
// }
// }
// rep(ej,ew) {
// int j = ys[ej];
// rep(i,h) {
// if (xs.in(i)) continue;
// g.add(i,h+j);
// }
// }
// rep(i,h) {
// if (xs.in(i)) g.add(sv,i,a[i]);
// else {
// int now = max(0,a[i]-dw);
// g.add(sv,i,now);
// }
// }
// rep(j,w) {
// if (ys.in(j)) g.add(h+j,tv,b[j]);
// else {
// int now = max(0,b[j]-dh);
// g.add(h+j,tv,now);
// }
// }
// g.solve(sv,tv);
// vi ta = a, tb = b;
// int e = 0;
// rep(ei,eh) {
// int i = xs[ei];
// rep(j,w) {
// if (ys.in(j)) continue;
// if (!g.lim[e]) tb[j]--;
// e += 2;
// }
// }
// rep(ej,ew) {
// int j = ys[ej];
// rep(i,h) {
// if (xs.in(i)) continue;
// if (!g.lim[e]) ta[i]--;
// e += 2;
// }
// }
// rep(i,h) if (!xs.in(i) && ta[i] > dw) dame;
// rep(j,w) if (!ys.in(j) && tb[j] > dh) dame;
// int ne = sz(g.lim);
// rep(ei,eh) {
// int i = xs[ei];
// rep(ej,ew) {
// int j = ys[ej];
// if (ans[i][j] == 'x') continue;
// g.add(i,h+j);
// }
// }
// rep(i,h) {
// if (xs.in(i)) continue;
// g.add(sv,i, min(a[i],dw));
// }
// rep(j,w) {
// if (ys.in(j)) continue;
// g.add(h+j,tv, min(b[j],dh));
// }
// g.solve(sv,tv);
auto add = [&](int i, int j) {
ans[i][j] = 'o';
a[i]--;
b[j]--;
};
// e = 0;
// rep(ei,eh) {
// int i = xs[ei];
// rep(j,w) {
// if (ys.in(j)) continue;
// if (!g.lim[e]) add(i,j);
// e += 2;
// }
// }
// rep(ej,ew) {
// int j = ys[ej];
// rep(i,h) {
// if (xs.in(i)) continue;
// if (!g.lim[e]) add(i,j);
// e += 2;
// }
// }
// e = ne;
// rep(ei,eh) {
// int i = xs[ei];
// rep(ej,ew) {
// int j = ys[ej];
// if (ans[i][j] == 'x') continue;
// if (!g.lim[e]) add(i,j);
// e += 2;
// }
// }
// rep(ei,eh) if (a[xs[ei]]) dame;
// rep(ej,ew) if (b[ys[ej]]) dame;
// vi is, js;
// rep(i,h) if (!xs.in(i)) is.pb(i);
// rep(j,w) if (!ys.in(j)) js.pb(j);
// for (int i : is) {
// vp nj;
// for (int j : js) nj.eb(b[j],j);
// sort(rrng(nj));
// int na = a[i];
// rep(k,na) add(i,nj[k].se);
// }
int sv = h+w, tv = sv+1;
Maxflow g(tv+1);
vi oa = a, ob = b;
vvi ng(h,vi(w));
rep(i,h) {
vp nj;
rep(j,w) nj.eb(b[j],j);
sort(rrng(nj));
rep(k,a[i]) {
int j = nj[k].se;
ng[i][j] = 1;
b[j]--;
}
a[i] = 0;
}
rep(j,w) if (b[j]) dame;
int e = 0;
rep(i,h)rep(j,w) {
if (ans[i][j] == 'x') {
if (!ng[i][j]) continue;
a[i]++; b[j]++;
} else {
g.add(i,h+j);
if (ng[i][j]) {
g.lim[e] = 0;
g.lim[e^1] = 1;
}
e += 2;
}
}
rep(i,h) if (a[i]) g.add(sv,i,a[i]);
rep(j,w) if (b[j]) g.add(h+j,tv,b[j]);
g.solve(sv,tv);
a = oa; b = ob;
e = 0;
rep(i,h)rep(j,w) {
if (ans[i][j] == 'x') continue;
if (!g.lim[e]) add(i,j);
e += 2;
}
rep(i,h) if (a[i]) dame;
rep(j,w) if (b[j]) dame;
cout<<"Yay!"<<endl;
rep(i,h) cout<<ans[i]<<endl;
return 0;
}
snuke