-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
eric
committed
Mar 27, 2021
1 parent
9b97301
commit c5ea5c6
Showing
6 changed files
with
425 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef vector<int> vi; | ||
typedef vector<vi> vvi; | ||
typedef long long ll; | ||
const ll INF = 1e9; | ||
//push relabel | ||
//O(n+m) memory | ||
//wack runtime | ||
class PR { | ||
private: | ||
typedef ll Flow; | ||
struct Edge { | ||
int dest, back; | ||
Flow f,c; | ||
}; | ||
vector<vector<Edge> > g; | ||
vector<Flow> ec; | ||
vector<Edge*> cur; | ||
vvi hs; | ||
vi H; | ||
public: | ||
PR(int n) { | ||
g.assign(n,vector<Edge>()); | ||
ec.assign(n,0); | ||
cur.assign(n,nullptr); | ||
hs.assign(2*n,vi()); | ||
H.assign(n,0); | ||
} | ||
void add(int s, int t, Flow cap, Flow rcap=0) { | ||
if(s == t) return; | ||
Edge a = {t,int(g[t].size()),0,cap}; | ||
Edge b = {s,int(g[s].size()),0,rcap}; | ||
g[s].push_back(a); | ||
g[t].push_back(b); | ||
} | ||
void addf(Edge& e, Flow f) { | ||
Edge& back = g[e.dest][e.back]; | ||
if(!ec[e.dest] && f) {hs[H[e.dest]].push_back(e.dest);} | ||
e.f += f;e.c -= f; | ||
ec[e.dest] += f; | ||
back.f -= f; | ||
back.c += f; | ||
ec[back.dest] -= f; | ||
} | ||
Flow maxflow(int s, int t) { | ||
int v = g.size(); | ||
H[s] = v;ec[t] = 1; | ||
vi co(2*v); | ||
co[0] = v-1; | ||
for(int i=0;i<v;i++) {cur[i] = g[i].data();} | ||
for(auto& e: g[s]) { | ||
addf(e,e.c); | ||
} | ||
for(int hi = 0;;) { | ||
while(hs[hi].empty()) {if(!hi--) return -ec[s];} | ||
int u = hs[hi].back();hs[hi].pop_back(); | ||
while(ec[u] > 0) { | ||
if(cur[u] == g[u].data() + g[u].size()) { | ||
H[u] = 1e9; | ||
for(auto& e: g[u]) { | ||
if(e.c && H[u] > H[e.dest]+1) { | ||
H[u] = H[e.dest]+1;cur[u] = &e; | ||
} | ||
} | ||
if(++co[H[u]],!--co[hi] && hi < v) { | ||
for(int i=0;i<v;i++) { | ||
if(hi < H[i] && H[i] < v) {--co[H[i]];H[i] = v+1;} | ||
} | ||
} | ||
hi = H[u]; | ||
} else if(cur[u] -> c && H[u] == H[cur[u]->dest]+1) { | ||
addf(*cur[u],min(ec[u],cur[u]->c)); | ||
} else { | ||
++cur[u]; | ||
} | ||
} | ||
} | ||
return -1; | ||
} | ||
bool leftMinCut(int a) { | ||
return H[a] >= g.size(); | ||
} | ||
|
||
}; | ||
|
||
const int dr[4] = {0,1,0,-1}; | ||
const int dc[4] = {1,0,-1,0}; | ||
typedef vector<ll> vl; | ||
int main() { | ||
ll n,m,k; | ||
cin >> n >> m >> k; | ||
PR pr(2*n*m+2); | ||
int SO = 2*n*m; | ||
int TO = 2*n*m+1; | ||
for(int i=0;i<m;i++) { | ||
for(int j=0;j<n;j++) { | ||
int lo = n*m+i*n+j; | ||
for(int di=0;di<4;di++) { | ||
int u = i+dr[di]; | ||
int v = j+dc[di]; | ||
if(u < 0 || u >= m) { | ||
pr.add(lo,TO,INF); | ||
continue; | ||
} | ||
if(v < 0 || v >= n) { | ||
pr.add(lo,TO,INF); | ||
continue; | ||
} | ||
int go = u*n+v; | ||
pr.add(lo,go,INF); | ||
} | ||
} | ||
} | ||
vector<string> ew; | ||
for(int i=0;i<m;i++) { | ||
string s; | ||
cin >> s; | ||
ew.push_back(s); | ||
} | ||
vl ka; | ||
for(int i=0;i<k;i++) { | ||
ll t; | ||
cin >> t; | ||
ka.push_back(t); | ||
} | ||
for(int i=0;i<m;i++) { | ||
string& s = ew[i]; | ||
for(int j=0;j<n;j++) { | ||
int fo = i*n+j; | ||
int no = n*m+fo; | ||
if(s[j] == 'B') { | ||
pr.add(SO,fo,INF); | ||
pr.add(fo,no,INF); | ||
} else if(s[j] >= 'a' && s[j] <= 'z') { | ||
pr.add(fo,no,ka[s[j]-'a']); | ||
} else { | ||
pr.add(fo,no,INF); | ||
} | ||
} | ||
} | ||
ll res = pr.maxflow(SO,TO); | ||
if(res >= INF) { | ||
cout << -1 << '\n'; | ||
} else { | ||
cout << res << '\n'; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include <bits/stdc++.h> | ||
#include <ext/pb_ds/assoc_container.hpp> | ||
#include <ext/pb_ds/tree_policy.hpp> | ||
#define fore(b,c) for(int val0=b;val0<c;val0++) | ||
#define forr(k,c,s) for(int k=c;k<s;k++) | ||
#define pb push_back | ||
#define mmp make_pair | ||
using namespace __gnu_pbds; | ||
using namespace std; | ||
template<typename T> | ||
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; | ||
|
||
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); | ||
typedef pair<int,int> ii; | ||
typedef long long ll; | ||
typedef vector<int> vi; | ||
typedef vector<ii> vii; | ||
typedef vector<vi> vvi; | ||
typedef long double ld; | ||
typedef vector<vii> al; | ||
typedef vector<ll> vl; | ||
const int INF = 1e9; | ||
const ll INFL = 1LL<<61; | ||
const int H = 4; | ||
vl ans; | ||
struct P { | ||
int x,y,idx; | ||
}; | ||
vector<vector<P>> st[H]; | ||
int find(const P& pt, int s) { | ||
if(pt.x*2 < s) { | ||
if(pt.y*2 < s) { | ||
return 0; | ||
} else { | ||
return 1; | ||
} | ||
} else { | ||
if(pt.y*2 < s) { | ||
return 3; | ||
} else { | ||
return 2; | ||
} | ||
} | ||
} | ||
P tra(const P& pt, int qu, int s) { | ||
switch(qu) { | ||
case 0: { | ||
return {pt.y*2,pt.x*2,pt.idx}; | ||
} | ||
case 1: { | ||
return {pt.x*2,pt.y*2-s,pt.idx}; | ||
} | ||
case 2: { | ||
return {pt.x*2-s,pt.y*2-s,pt.idx}; | ||
} | ||
case 3: { | ||
return {s-(pt.y*2),s-(pt.x*2-s),pt.idx}; | ||
} | ||
} | ||
return pt; | ||
} | ||
void proc(int idx, int s) { | ||
for(int id=0;id<H;id++) { | ||
if(st[id][idx].size() == 0) {continue;} | ||
if(st[id][idx].size() == 1) { | ||
ans.push_back(st[id][idx].front().idx); | ||
continue; | ||
} | ||
for(int i=0;i<H;i++) { | ||
st[i].emplace_back(); | ||
} | ||
for(const auto& it: st[id][idx]) { | ||
int ni = find(it,s); | ||
st[ni][idx+1].push_back(tra(it,ni,s)); | ||
} | ||
proc(idx+1,s); | ||
for(int i=0;i<H;i++) { | ||
st[i].pop_back(); | ||
} | ||
} | ||
} | ||
int main() { | ||
ios::sync_with_stdio(0);cout.precision(20);cout.tie(0);cin.tie(0); | ||
ll n,sz; | ||
cin >> n >> sz; | ||
for(int i=0;i<H;i++) { | ||
st[i].emplace_back(); | ||
} | ||
vii go; | ||
for(int i=0;i<n;i++) { | ||
int a,b; | ||
cin >> a >> b; | ||
st[0][0].push_back({a,b,i}); | ||
go.emplace_back(a,b); | ||
} | ||
proc(0,sz); | ||
for(int i=0;i<ans.size();i++) { | ||
ii po = go[ans[i]]; | ||
cout << po.first << " " << po.second << '\n'; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include <bits/stdc++.h> | ||
#include <ext/pb_ds/assoc_container.hpp> | ||
#include <ext/pb_ds/tree_policy.hpp> | ||
#define fore(b,c) for(int val0=b;val0<c;val0++) | ||
#define forr(k,c,s) for(int k=c;k<s;k++) | ||
#define pb push_back | ||
#define mmp make_pair | ||
using namespace __gnu_pbds; | ||
using namespace std; | ||
template<typename T> | ||
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; | ||
|
||
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); | ||
typedef pair<int,int> ii; | ||
typedef long long ll; | ||
typedef vector<int> vi; | ||
typedef vector<ii> vii; | ||
typedef vector<vi> vvi; | ||
typedef long double ld; | ||
typedef vector<vii> al; | ||
typedef vector<ll> vl; | ||
typedef pair<ll,ll> pl; | ||
const int INF = 1e9; | ||
const ll INFL = 1LL<<61; | ||
class ST { | ||
private: | ||
int n; | ||
vl st; | ||
public: | ||
ST(int n_) { | ||
n = n_; | ||
st.assign(2*n,0); | ||
} | ||
void up(int p, ll v) { | ||
p += n; | ||
st[p] = v; | ||
while(p > 1) { | ||
st[p>>1] = max(st[p],st[p^1]); | ||
p >>= 1; | ||
} | ||
} | ||
ll get(int l, int r) { | ||
l += n;r += n; | ||
ll res = -INFL; | ||
for(;l<r;l>>=1,r>>=1) { | ||
if(l&1) { | ||
res = max(res,st[l]); | ||
l++; | ||
} | ||
if(r&1) { | ||
--r; | ||
res = max(res,st[r]); | ||
} | ||
} | ||
return res; | ||
} | ||
}; | ||
int main() { | ||
ios::sync_with_stdio(0);cout.precision(20);cout.tie(0);cin.tie(0); | ||
ll n,ra,wo,ho; | ||
cin >> n >> ra >> wo >> ho; | ||
vector<pl> w; | ||
for(int i=0;i<n;i++) { | ||
ll x,y; | ||
cin >> x >> y; | ||
x *= 2*ra;y *= 2*ra; | ||
w.emplace_back(x+y/ra,y); | ||
} | ||
sort(w.begin(),w.end()); | ||
vl ms; | ||
for(int i=0;i<w.size();i++) { | ||
w[i].second = w[i].second-ra*w[i].first/2; | ||
ms.push_back(w[i].second); | ||
} | ||
sort(ms.begin(),ms.end()); | ||
ST st(w.size()+3); | ||
for(int i=w.size()-1;i>=0;i--) { | ||
int idx = lower_bound(ms.begin(),ms.end(),w[i].second)-ms.begin(); | ||
ll gu = st.get(idx,w.size()); | ||
st.up(idx,gu+1); | ||
} | ||
ll res = st.get(0,w.size()); | ||
cout << res << '\n'; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
typedef long double ld; | ||
typedef vector<ll> vl; | ||
const int A = 26; | ||
int main() { | ||
cout.precision(20); | ||
string s; | ||
cin >> s; | ||
vl kt(A,0); | ||
for(int i=0;i<s.size();i++) { | ||
kt[s[i]-'a']++; | ||
} | ||
sort(kt.begin(),kt.end()); | ||
ll ma = kt[A-1]+kt[A-2]; | ||
cout << s.size()-ma << '\n'; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
typedef long double ld; | ||
typedef vector<ll> vl; | ||
const int A = 26; | ||
int main() { | ||
cout.precision(20); | ||
int n,m; | ||
cin >> n >> m; | ||
vl wa,wb; | ||
for(int i=0;i<n;i++) { | ||
int t; | ||
cin >> t; | ||
wa.push_back(t); | ||
} | ||
for(int i=0;i<m;i++) { | ||
int t; | ||
cin >> t; | ||
wb.push_back(t); | ||
} | ||
sort(wb.begin(),wb.end()); | ||
set<int> bs; | ||
for(int i=0;i<n;i++) { | ||
int mi = 0; | ||
for(int j=0;j<m;j++) { | ||
if(abs(wb[j]-wa[i]) < abs(wb[mi]-wa[i])) { | ||
mi = j; | ||
} | ||
} | ||
bs.insert(mi); | ||
} | ||
cout << wa.size()-bs.size() << '\n'; | ||
} | ||
|
Oops, something went wrong.