text
stringlengths 49
983k
|
|---|
#include <bits/stdc++.h>
using namespace std;
int N, cho[(100010)], num[8];
map<string, int> M;
vector<int> vec[(100010)], can[8];
string sze[8];
inline bool judge() {
for (int i = 1; i <= N; ++i) {
if (vec[i].size() == 1) {
if (num[vec[i][0]])
num[vec[i][0]]--, cho[i] = vec[i][0];
else
return false;
} else {
if (vec[i][0] > vec[i][1]) swap(vec[i][0], vec[i][1]);
can[vec[i][0]].push_back(i);
}
}
for (int i = 1; i <= 5; ++i)
for (int j = 0; j < can[i].size(); ++j)
for (int k = 0; k < 2; ++k)
if (num[vec[can[i][j]][k]]) {
num[vec[can[i][j]][k]]--, cho[can[i][j]] = vec[can[i][j]][k];
break;
}
for (int i = 1; i <= N; ++i)
if (!cho[i]) return false;
return true;
}
int main() {
for (int i = 1; i <= 6; ++i) scanf("%d", num + i);
sze[1] = "S";
sze[2] = "M";
sze[3] = "L";
sze[4] = "XL";
sze[5] = "XXL";
sze[6] = "XXXL";
for (int i = 1; i <= 6; ++i) M[sze[i]] = i;
scanf("%d", &N);
for (int i = 1; i <= N; ++i) {
string s;
cin >> s;
int l = s.length(), j;
for (j = 0; j < l; ++j)
if (s[j] == ',') break;
if (j == l)
vec[i].push_back(M[s]);
else {
string t;
t = s.substr(j + 1);
s.erase(j);
vec[i].push_back(M[s]);
vec[i].push_back(M[t]);
}
}
if (!judge())
puts("NO");
else {
puts("YES");
for (int i = 1; i <= N; ++i) cout << sze[cho[i]] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<string> seperate(string &s) {
vector<string> vec;
int n = s.length();
string cur;
for (int i = 0; i < n; ++i) {
if (s[i] == ',') {
vec.emplace_back(cur);
cur = "";
}
cur += s[i];
}
return vec;
}
int num[6], n, m, c[100000];
vector<string> a[100000];
map<string, int> map1;
map<int, string> map2;
vector<int> to[11];
void body() {
map1["S"] = 0;
map1["M"] = 1;
map1["L"] = 2;
map1["XL"] = 3;
map1["XXL"] = 4;
map1["XXXL"] = 5;
map2[0] = "S";
map2[1] = "M";
map2[2] = "L";
map2[3] = "XL";
map2[4] = "XXL";
map2[5] = "XXXL";
for (int i = 0; i < 6; ++i) {
cin >> num[i];
}
cin >> n;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
s += ",";
a[i] = seperate(s);
int v = map1[a[i][0]] * 2;
to[v + (a[i].size() > 1)].emplace_back(i);
}
int cur_size = 0;
bool okay = 1;
for (int i = 0; i < 11; ++i) {
int L = i / 2, R = i / 2 + i % 2;
for (auto e : to[i]) {
if (num[L] > 0) {
c[e] = L;
--num[L];
} else {
if (num[R] > 0) {
c[e] = R;
--num[R];
} else {
okay = 0;
break;
}
}
}
}
if (!okay) {
cout << "NO\n";
} else {
cout << "YES\n";
for (int i = 0; i < n; ++i) {
cout << map2[c[i]] << "\n";
}
}
}
void init() { ios::sync_with_stdio(0); }
int main() {
init();
body();
}
|
#include <bits/stdc++.h>
using namespace std;
int ct[7];
int ans[100001];
stack<int> arr[6];
map<int, string> m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, i, j, t;
string temp;
m[1] = "S";
m[2] = "M";
m[3] = "L";
m[4] = "XL";
m[5] = "XXL";
m[6] = "XXXL";
string s;
for (i = 1; i <= 6; i++) {
cin >> ct[i];
}
cin >> n;
for (i = 1; i <= n; i++) {
cin >> s;
for (j = 1; j <= 6; j++) {
if (s == m[j]) {
ans[i] = j;
ct[j]--;
if (ct[j] < 0) {
cout << "NO\n";
return 0;
}
break;
}
}
for (j = 1; j <= 5; j++) {
temp = m[j] + ",";
temp = temp + m[j + 1];
if (s == temp) {
arr[j].push(i);
break;
}
}
}
for (i = 1; i <= 5; i++) {
while (ct[i] > 0 && arr[i].size()) {
t = arr[i].top();
arr[i].pop();
ans[t] = i;
ct[i]--;
}
if (ct[i + 1] < arr[i].size()) {
cout << "NO\n";
return 0;
}
while (arr[i].size()) {
t = arr[i].top();
arr[i].pop();
ans[t] = i + 1;
ct[i + 1]--;
}
}
cout << "YES\n";
for (i = 1; i <= n; i++) {
cout << m[ans[i]] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1000000007;
int ans[100005];
int tot[6];
map<string, int> toInt;
vector<int> want[6];
string toStr[6];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
toInt["S"] = 0;
toStr[0] = "S";
toInt["M"] = 1;
toStr[1] = "M";
toInt["L"] = 2;
toStr[2] = "L";
toInt["XL"] = 3;
toStr[3] = "XL";
toInt["XXL"] = 4;
toStr[4] = "XXL";
toInt["XXXL"] = 5;
toStr[5] = "XXXL";
for (int i = (0); i < (6); i++) cin >> tot[i];
int n;
cin >> n;
for (int i = (0); i < (n); i++) {
string s;
cin >> s;
string a, b = "!";
for (char c : s) {
if (b != "!")
b += c;
else if (c == ',')
b = "";
else
a += c;
}
if (b == "!") {
ans[i] = toInt[a];
tot[ans[i]]--;
} else
want[toInt[a]].push_back(i);
}
for (int i = (0); i < (6); i++) {
if (tot[i] < 0) {
cout << "NO" << endl;
return 0;
}
}
for (int i = (0); i < (6); i++) {
for (int& v : want[i]) {
if (tot[i]) {
tot[i]--;
ans[v] = i;
} else {
if (!tot[i + 1]) {
cout << "NO" << endl;
return 0;
}
tot[i + 1]--;
ans[v] = i + 1;
}
}
}
cout << "YES" << endl;
for (int i = (0); i < (n); i++) {
cout << toStr[ans[i]] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int T_cnt[8], n, cloth[100005];
char s[20], a[20], b[20];
char T_sh[6][5] = {"S", "M", "L", "XL", "XXL", "XXXL"};
vector<pair<int, int> > q;
inline int Getid(const char *s) {
if (s[0] == 'S') return 0;
if (s[0] == 'M') return 1;
if (s[0] == 'L') return 2;
if (s[1] == 'L') return 3;
if (s[2] == 'L') return 4;
if (s[3] == 'L') return 5;
}
int main() {
for (int i = 0; i < 6 && scanf("%d", &T_cnt[i]); i++)
;
scanf("%d", &n);
getchar();
for (int i = 0; i < n && scanf("%[^\n]s", s) && getchar(); i++) {
for (int j = 0; s[j]; j++)
if (s[j] == ',') {
s[j] = ' ';
break;
}
int status = sscanf(s, "%s%s", a, b), ID = Getid(a);
if (status == 1) {
if (T_cnt[ID] > 0)
T_cnt[ID]--, cloth[i] = ID;
else
return puts("NO"), 0;
} else
q.emplace_back(make_pair(ID, i));
}
sort(q.begin(), q.end());
for (auto item : q) {
if (T_cnt[item.first] > 0)
T_cnt[item.first]--, cloth[item.second] = item.first;
else if (item.first == 5 || !T_cnt[item.first + 1])
return puts("NO"), 0;
else
T_cnt[item.first + 1]--, cloth[item.second] = item.first + 1;
}
puts("YES");
for (int i = 0; i < n; i++) puts(T_sh[cloth[i]]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ans[100001];
int prefer[100001];
vector<int> v[6];
string data[] = {"S", "M", "L", "XL", "XXL", "XXXL"};
bool cmp(int x, int y) { return prefer[x] < prefer[y]; }
int which(string x) {
for (int i = 0; i < 6; i++) {
if (x == data[i]) return i;
}
}
int main() {
int a[6];
for (int i = 0; i < 6; i++) {
cin >> a[i];
}
int n;
cin >> n;
memset(ans, -1, sizeof ans);
string s;
for (int i = 0; i < n; i++) {
cin >> s;
if (s.find(',') == string::npos) {
int x = which(s);
if (a[x] < 1) {
cout << "NO\n";
return 0;
}
ans[i] = x;
a[x]--;
} else {
int a = which(s.substr(0, s.find(',')));
int b = which(s.substr(s.find(',') + 1));
v[a].push_back(i);
v[b].push_back(i);
prefer[i] = min(a, b);
}
}
for (int i = 0; i < 6; i++) {
sort(v[i].begin(), v[i].end(), cmp);
for (auto z : v[i]) {
if (ans[z] == -1 && a[i] > 0) {
a[i]--;
ans[z] = i;
}
}
}
for (int i = 0; i < n; i++) {
if (ans[i] == -1) {
cout << "NO";
return 0;
}
}
cout << "YES\n";
for (int i = 0; i < n; i++) {
cout << data[ans[i]] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxi = 1e5 + 9;
int arr[6];
string str[maxi];
int main() {
string sdou[5] = {"S,M", "M,L", "L,XL", "XL,XXL", "XXL,XXXL"};
string ssin[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
for (int i = 0; i < 6; i++) {
cin >> arr[i];
}
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> str[i];
for (int j = 0; j < 6; j++) {
if (str[i] == ssin[j]) arr[j]--;
}
}
for (int i = 0; i < 6; i++)
if (arr[i] < 0) return cout << "NO\n", 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < n; j++) {
if (str[j] == sdou[i]) {
if (arr[i] > 0) {
arr[i]--;
str[j] = ssin[i];
} else if (arr[i + 1] > 0) {
arr[i + 1]--;
str[j] = ssin[i + 1];
} else {
cout << "NO\n";
return 0;
}
}
}
}
cout << "YES\n";
for (int i = 0; i < n; i++) cout << str[i] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const char* szt[] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int szs[6];
struct one {
int num;
int s1;
};
struct dbl {
int num;
int s1, s2;
int sel;
friend bool operator<(const dbl& l, const dbl& r) {
if (l.s1 == r.s1) {
return l.s2 < r.s2;
}
return l.s1 < r.s1;
}
};
struct n_cmp {
bool operator()(const dbl& l, const dbl& r) { return l.num < r.num; }
};
int sz_to_sz(const string& s) {
int r;
if (s == "S") {
r = 0;
} else if (s == "M") {
r = 1;
} else if (s == "L") {
r = 2;
} else if (s == "XL") {
r = 3;
} else if (s == "XXL") {
r = 4;
} else if (s == "XXXL") {
r = 5;
}
return r;
}
bool is_valid() {
for (int i = 0; i < 6; i++) {
if (szs[i] < 0) {
return false;
}
}
return true;
}
int main() {
for (int i = 0; i < 6; i++) {
cin >> szs[i];
}
int n;
cin >> n;
vector<one> ones;
vector<dbl> dbls;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
auto r = str.find(",");
if (r == -1) {
one o;
o.num = i + 1;
o.s1 = sz_to_sz(str);
ones.push_back(o);
} else {
dbl d;
d.num = i + 1;
d.s1 = sz_to_sz(str.substr(0, r));
d.s2 = sz_to_sz(str.substr(r + 1, str.size() - r - 1));
dbls.push_back(d);
}
}
for (int i = 0; i < ones.size(); i++) {
szs[ones[i].s1]--;
}
sort(dbls.begin(), dbls.end());
if (!is_valid()) {
cout << "NO";
return 0;
}
for (int i = 0; i < dbls.size(); i++) {
if (szs[dbls[i].s1] > 0) {
szs[dbls[i].s1]--;
dbls[i].sel = dbls[i].s1;
} else {
szs[dbls[i].s2]--;
dbls[i].sel = dbls[i].s2;
}
}
if (!is_valid()) {
cout << "NO";
return 0;
}
n_cmp tmp;
sort(dbls.begin(), dbls.end(), tmp);
cout << "YES" << endl;
int i = 0, j = 0;
while (i < ones.size() && j < dbls.size()) {
if (ones[i].num < dbls[j].num) {
cout << szt[ones[i].s1] << endl;
i++;
} else {
cout << szt[dbls[j].sel] << endl;
j++;
}
}
for (; i < ones.size(); i++) {
cout << szt[ones[i].s1] << endl;
}
for (; j < dbls.size(); j++) {
cout << szt[dbls[j].sel] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
namespace MF {
const int N = 500, M = 10000;
int f[N], e[2 * M], c[2 * M], fl[2 * M], nxt[2 * M], ce;
int n, s, t;
int Q[N], lvl[N];
int le[N];
void init(int _n) {
n = _n + 2, s = _n, t = _n + 1;
ce = 0;
for (int i = (0); i < (n); i++) f[i] = -1;
}
int add(int a, int b, int cap) {
nxt[ce] = f[a];
f[a] = ce;
e[ce] = b;
fl[ce] = 0;
c[ce] = cap;
ce++;
nxt[ce] = f[b];
f[b] = ce;
e[ce] = a;
fl[ce] = 0;
c[ce] = 0;
ce++;
return ce - 2;
}
bool bfs() {
for (int i = (0); i < (n); i++) lvl[i] = -1;
int qi = 1;
Q[0] = s;
lvl[s] = 0;
for (int i = (0); i < (qi); i++) {
int x = Q[i];
le[x] = f[x];
for (int j = f[x]; j >= 0; j = nxt[j])
if (c[j] - fl[j] > 0) {
int y = e[j];
if (lvl[y] == -1) {
lvl[y] = lvl[x] + 1;
Q[qi++] = y;
}
}
}
return lvl[t] != -1;
}
int aug(int cu, int cf) {
if (cu == t) return cf;
for (int &i = le[cu]; i >= 0; i = nxt[i])
if (c[i] - fl[i] > 0) {
int x = e[i];
if (lvl[x] != lvl[cu] + 1) continue;
int rf = aug(x, min(cf, c[i] - fl[i]));
if (rf > 0) {
fl[i] += rf;
fl[i ^ 1] -= rf;
assert(fl[i] == -fl[i ^ 1]);
return rf;
}
}
lvl[cu] = -1;
return 0;
}
int mf() {
int tot = 0;
while (bfs())
for (int x = aug(s, 1e9); x; x = aug(s, 1e9)) tot += x;
return tot;
}
} // namespace MF
string lst[] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int N, occ[6], sz[50], ans[100100];
vector<int> adj[50];
vector<int> id[50];
char buf[50];
pair<int, int> shit[50];
int main() {
for (int i = (0); i < (6); i++) scanf("%d", &occ[i]);
scanf("%d", &N);
for (int i = (0); i < (N); i++) {
scanf(" %s", buf);
string in(buf), a, b;
bool passed = 0;
for (int j = (0); j < ((int)in.size()); j++) {
if (in[j] == ',')
passed = 1;
else {
if (passed)
b += in[j];
else
a += in[j];
}
}
int x = -1, y = -1;
for (int j = (0); j < (6); j++)
if (a == lst[j]) x = j;
for (int j = (0); j < (6); j++)
if (b == lst[j]) y = j;
if (y == -1) y = x;
if (y < x) swap(x, y);
sz[x * 6 + y]++;
id[x * 6 + y].push_back(i);
}
MF::init(50);
for (int i = (0); i < (6); i++)
for (int j = (i); j < (6); j++) {
int x = i * 6 + j;
MF::add(MF::s, x, sz[x]);
if (i == j) {
shit[x].first = MF::add(x, 36 + i, sz[x]);
} else {
shit[x].first = MF::add(x, 36 + i, sz[x]);
shit[x].second = MF::add(x, 36 + j, sz[x]);
}
}
for (int i = (36); i < (36 + 6); i++) {
MF::add(i, MF::t, occ[i - 36]);
}
int res = MF::mf();
if (res == N) {
puts("YES");
for (int i = (0); i < (6); i++)
for (int j = (i); j < (6); j++) {
int x = i * 6 + j;
if (i == j) {
for (int v : id[x]) ans[v] = i;
} else {
assert(MF::fl[shit[x].first] + MF::fl[shit[x].second] == sz[x]);
for (int rep = (0); rep < (MF::fl[shit[x].first]); rep++)
ans[id[x].back()] = i, id[x].pop_back();
for (int v : id[x]) ans[v] = j;
}
}
for (int i = (0); i < (N); i++) printf("%s\n", lst[ans[i]].c_str());
} else
puts("NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
map<int, string> shirt;
map<string, int> m;
vector<int> want[maxn];
int ans[maxn], p[10];
string s, buf;
int main() {
int i, j, n;
scanf("%d %d %d %d %d %d", &p[1], &p[2], &p[3], &p[4], &p[5], &p[6]);
scanf("%d", &n);
shirt[1] = "S";
shirt[2] = "M";
shirt[3] = "L";
shirt[4] = "XL";
shirt[5] = "XXL";
shirt[6] = "XXXL";
m["S"] = 1;
m["M"] = 2;
m["L"] = 3;
m["XL"] = 4;
m["XXL"] = 5;
m["XXXL"] = 6;
int num = 0;
bool ok = true;
for (i = 1; i <= n; i++) {
cin >> s;
int len = s.size();
for (j = 0; j < len; j++) {
if (s[j] == ',') {
s[j] = ' ';
}
}
stringstream ss(s);
while (ss >> buf) {
want[num].push_back(m[buf]);
}
num++;
}
for (j = 0; j < num && ok; j++) {
if (want[j].size() == 1) {
if (p[want[j][0]]) {
ans[j] = want[j][0];
p[want[j][0]]--;
} else
ok = false;
}
}
if (!ok) {
printf("NO\n");
return 0;
}
for (i = 0; i <= 4 && ok; i++) {
for (j = 0; j < num && ok; j++) {
if (want[j].size() == 2 && want[j][0] == 1 + i && want[j][1] == 2 + i) {
if (p[i + 1]) {
ans[j] = i + 1;
p[i + 1]--;
} else if (p[i + 2]) {
ans[j] = i + 2;
p[i + 2]--;
} else
ok = false;
}
}
}
if (!ok)
printf("NO\n");
else {
printf("YES\n");
for (i = 0; i < n; i++) cout << shirt[ans[i]] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int p1, p2, n, p3, quantity;
bool isPossible = true;
map<int, string> mp1;
map<int, int> mp2, mp3;
map<int, int>::iterator it;
vector<string> result;
string str;
cin >> quantity;
mp1[0] = "S";
mp2[0] = quantity;
cin >> quantity;
mp1[1] = "M";
mp2[1] = quantity;
cin >> quantity;
mp1[2] = "L";
mp2[2] = quantity;
cin >> quantity;
mp1[3] = "XL";
mp2[3] = quantity;
cin >> quantity;
mp1[4] = "XXL";
mp2[4] = quantity;
cin >> quantity;
mp1[5] = "XXXL";
mp2[5] = quantity;
cin >> n;
vector<vector<string> > request(n);
for (p1 = 0; p1 < n; p1++) {
cin >> str;
for (p2 = 0; p2 < str.size() && str[p2] != ','; p2++)
;
request[p1].push_back(str.substr(0, p2));
p2++;
p3 = p2;
while (p2 < str.size()) p2++;
if (p2 != p3) request[p1].push_back(str.substr(p3, p2 - p3));
}
for (it = mp2.begin(); it != mp2.end(); it++) {
for (p1 = 0; p1 < n && it->second > 0; p1++) {
if (request[p1].size() > 1) continue;
if (request[p1][0] == mp1[it->first]) {
mp3[p1]++;
it->second--;
}
}
for (p1 = 0; p1 < n && it->second > 0; p1++) {
if (request[p1].size() > 1 && request[p1][0] == mp1[it->first]) {
request[p1].pop_back();
mp3[p1]++;
it->second--;
} else if (request[p1].size() > 1 && request[p1][1] == mp1[it->first]) {
request[p1].erase(request[p1].begin());
mp3[p1]++;
it->second--;
}
}
for (; p1 < n; p1++) {
if (request[p1].size() <= 1) continue;
if (request[p1][0] == mp1[it->first])
request[p1].erase(request[p1].begin());
else if (request[p1][1] == mp1[it->first])
request[p1].pop_back();
}
}
for (p1 = 0; p1 < n; p1++)
if (request[p1].size() > 1) isPossible = false;
if (mp3.size() != n) isPossible = false;
if (!isPossible) {
cout << "NO";
} else {
cout << "YES" << endl;
for (p1 = 0; p1 < n; p1++) cout << request[p1][0] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long MAX5 = 1e+5 + 7;
const long long MAX7 = 1e+7 + 7;
const long long MAXN = MAX7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const long long MOD = 998244353;
long long t = 1;
long long n;
string second;
vector<string> removeDupWord(string str) {
vector<string> val;
string word = "";
for (auto x : str) {
if (x == ',') {
val.push_back(word);
word = "";
} else {
word = word + x;
}
}
val.push_back(word);
return val;
}
void MAIN() {
vector<long long> size(6);
for (long long i = 0; i < 6; i++) cin >> size[i];
map<long long, string> indx;
indx[0] = "S";
indx[1] = "M";
indx[2] = "L";
indx[3] = "XL";
indx[4] = "XXL";
indx[5] = "XXXL";
cin >> n;
vector<string> val[n];
vector<string> ans(n, "-");
for (long long i = 0; i < n; i++) {
cin >> second;
val[i] = removeDupWord(second);
}
for (long long k = 0; k < 6; k++) {
second = indx[k];
for (long long i = 0; i < n; i++) {
if (val[i].size() == 1 && val[i][0] == second) {
if (size[k]) {
size[k]--;
ans[i] = second;
} else {
cout << "NO\n";
return;
}
}
}
for (long long i = 0; i < n; i++) {
if (val[i].size() == 2 && val[i][1] == second && ans[i] == "-") {
if (size[k]) {
size[k]--;
ans[i] = second;
} else {
cout << "NO\n";
return;
}
}
}
for (long long i = 0; i < n; i++) {
if (val[i].size() == 2 && val[i][0] == second) {
if (size[k]) {
size[k]--;
ans[i] = second;
}
}
}
}
cout << "YES\n";
for (long long i = 0; i < n; i++) cout << ans[i] << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed;
cout << setprecision(12);
;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
;
while (t--) {
MAIN();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename flow_type>
struct dinic {
struct edge {
size_t src, dst, rev;
flow_type flow, cap;
};
int n;
vector<vector<edge>> adj;
dinic(int n) : n(n), adj(n), level(n), q(n), it(n) {}
void add_edge(size_t src, size_t dst, flow_type cap, flow_type rcap = 0) {
adj[src].push_back({src, dst, adj[dst].size(), 0, cap});
if (src == dst) adj[src].back().rev++;
adj[dst].push_back({dst, src, adj[src].size() - 1, 0, rcap});
}
vector<int> level, q, it;
bool bfs(int source, int sink) {
fill((level).begin(), (level).end(), -1);
for (int qf = level[q[0] = sink] = 0, qb = 1; qf < qb; ++qf) {
sink = q[qf];
for (edge &e : adj[sink]) {
edge &r = adj[e.dst][e.rev];
if (r.flow < r.cap && level[e.dst] == -1)
level[q[qb++] = e.dst] = 1 + level[sink];
}
}
return level[source] != -1;
}
flow_type augment(int source, int sink, flow_type flow) {
if (source == sink) return flow;
for (; it[source] != adj[source].size(); ++it[source]) {
edge &e = adj[source][it[source]];
if (e.flow < e.cap && level[e.dst] + 1 == level[source]) {
flow_type delta = augment(e.dst, sink, min(flow, e.cap - e.flow));
if (delta > 0) {
e.flow += delta;
adj[e.dst][e.rev].flow -= delta;
return delta;
}
}
}
return 0;
}
flow_type max_flow(int source, int sink) {
for (int u = 0; u < n; u++)
for (edge &e : adj[u]) e.flow = 0;
flow_type flow = 0;
flow_type oo = numeric_limits<flow_type>::max();
while (bfs(source, sink)) {
fill((it).begin(), (it).end(), 0);
for (flow_type f; (f = augment(source, sink, oo)) > 0;) flow += f;
}
return flow;
}
};
const int maxn = 100000 + 10;
const int maxt = 6;
map<string, int> idx;
map<int, string> idR;
int cnt[maxt];
vector<int> get(string A) {
int N = A.size();
vector<int> res;
int i = 0;
string str = "";
while (i < N) {
if (A[i] == ',') {
i++;
break;
}
str += A[i];
i++;
}
res.push_back(idx[str]);
str = "";
while (i < N) {
str += A[i];
i++;
}
if (str.size()) {
res.push_back(idx[str]);
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
idx["S"] = 1;
idx["M"] = 2;
idx["L"] = 3;
idx["XL"] = 4;
idx["XXL"] = 5;
idx["XXXL"] = 6;
idR[1] = "S";
idR[2] = "M";
idR[3] = "L";
idR[4] = "XL";
idR[5] = "XXL";
idR[6] = "XXXL";
for (int i = 0; i < 6; i++) cin >> cnt[i];
int N;
cin >> N;
dinic<int> dini(N + 8);
for (int i = 1; i < N + 1; i++) {
dini.add_edge(0, i, 1);
string str;
cin >> str;
vector<int> no = get(str);
for (auto &v : no) dini.add_edge(i, N + v, 1);
}
for (int i = 0; i < 6; i++) dini.add_edge(N + i + 1, N + 7, cnt[i]);
int flow = dini.max_flow(0, N + 7);
if (flow != N) {
cout << "NO\n";
return 0;
}
cout << "YES\n";
for (int i = 1; i < N + 1; i++) {
for (auto &act : dini.adj[i]) {
if (act.flow == 1) {
int v = act.dst - N;
cout << idR[v] << '\n';
break;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int cnt[10];
string size[] = {"S", "M", "L", "XL", "XXL", "XXXL"};
unordered_map<string, int> id{{"S", 0}, {"M", 1}, {"L", 2},
{"XL", 3}, {"XXL", 4}, {"XXXL", 5},
{"S,M", 6}, {"M,L", 7}, {"L,XL", 8},
{"XL,XXL", 9}, {"XXL,XXXL", 10}};
vector<int> cnt1[10], cnt2[10];
int p[maxn];
int main() {
for (int i = 0; i < 6; ++i) scanf("%d", cnt + i);
int _n;
scanf("%d", &_n);
string line;
for (int i = 0; i < _n; ++i) {
cin >> line;
int index = id[line];
if (index < 6)
cnt1[index].push_back(i);
else
cnt2[index - 6].push_back(i);
p[i] = index;
}
for (int i = 0; i < 6; ++i) {
cnt[i] -= cnt1[i].size();
if (cnt[i] < 0) {
cout << "NO\n";
return 0;
}
}
int pos = 0;
for (size_t i = 0; cnt[0] > 0 && i < cnt2[0].size(); ++i) {
p[cnt2[0][pos++]] = 0;
cnt[0]--;
}
for (size_t i = 0; i < 5; ++i) {
for (size_t j = pos; j < cnt2[i].size(); ++j) {
cnt[i + 1]--;
p[cnt2[i][j]] = i + 1;
}
if (cnt[i + 1] < 0) {
cout << "NO\n";
return 0;
}
pos = 0;
for (size_t j = 0; cnt[i + 1] > 0 && j < cnt2[i + 1].size(); ++j) {
cnt[i + 1]--;
p[cnt2[i + 1][pos++]] = i + 1;
}
}
if (cnt[5] < 0) {
cout << "NO\n";
return 0;
} else {
cout << "YES\n";
for (int i = 0; i < _n; ++i) {
cout << size[p[i]] << "\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
vector<string> results(100001);
vector<pair<int, string> > wishes;
vector<pair<int, string> > S_M, M_L, L_XL, XL_XXL, XXL_XXXL;
bool compare(pair<int, string> a, pair<int, string> b) {
if (a.second == "S,M") return false;
if (a.second == "M,L") return b.second == "S,M";
if (a.second == "L,XL") return b.second == "S,M" || b.second == "M,L";
if (a.second == "XL,XXL") return b.second != "XXL,XXXL";
return true;
}
int main() {
int S = 0, M = 0, L = 0, XL = 0, XXL = 0, XXXL = 0;
cin >> S >> M >> L >> XL >> XXL >> XXXL;
map<string, int> sizes;
sizes["S"] = S;
sizes["M"] = M;
sizes["L"] = L;
sizes["XL"] = XL;
sizes["XXL"] = XXL;
sizes["XXXL"] = XXXL;
int n;
string s;
cin >> n;
unsigned long long xx = 0;
for (int i = 0; i < n; i++) {
cin >> s;
int pos = s.find(",");
if (pos == string::npos) {
results[i] = s;
if (sizes[s] > 0)
sizes[s]--;
else {
cout << "NO";
return 0;
}
} else {
if (s == "S,M") S_M.push_back(make_pair(i, s));
if (s == "M,L") M_L.push_back(make_pair(i, s));
if (s == "L,XL") L_XL.push_back(make_pair(i, s));
if (s == "XL,XXL") XL_XXL.push_back(make_pair(i, s));
if (s == "XXL,XXXL") {
XXL_XXXL.push_back(make_pair(i, s));
xx++;
}
}
}
wishes.insert(wishes.end(), S_M.begin(), S_M.end());
wishes.insert(wishes.end(), M_L.begin(), M_L.end());
wishes.insert(wishes.end(), L_XL.begin(), L_XL.end());
wishes.insert(wishes.end(), XL_XXL.begin(), XL_XXL.end());
wishes.insert(wishes.end(), XXL_XXXL.begin(), XXL_XXXL.end());
for (int i = 0; i < wishes.size(); i++) {
pair<int, string> wish = wishes[i];
string sz = wish.second;
int ind = wish.first;
int pos = sz.find(",");
string first = sz.substr(0, pos);
string second = sz.substr(pos + 1);
if (sizes[first] == 0 && sizes[second] == 0) {
cout << "NO";
return 0;
}
if (sizes[first] != 0) {
results[ind] = first;
sizes[first]--;
} else {
results[ind] = second;
sizes[second]--;
}
}
cout << "YES" << endl;
for (int i = 0; i < n; i++) cout << results[i] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int r[100000];
vector<int> sms;
vector<int> mls;
vector<int> lxls;
vector<int> xlxxls;
vector<int> xxlxxxls;
void dec(int& c, int i, int v) {
if (c > 0) {
c--;
r[i] = v;
} else {
std::cout << "NO";
exit(0);
}
}
int main() {
int s, m, l, xl, xxl, xxxl;
cin >> s >> m >> l >> xl >> xxl >> xxxl;
int n;
cin >> n;
int sm, ml, lxl, xlxxl, xxlxxxl;
for (int i = 0; i < n; i++) {
string ss;
cin >> ss;
if (ss == "S") dec(s, i, 1);
if (ss == "M") dec(m, i, 2);
if (ss == "L") dec(l, i, 3);
if (ss == "XL") dec(xl, i, 4);
if (ss == "XXL") dec(xxl, i, 5);
if (ss == "XXXL") dec(xxxl, i, 6);
if (ss == "S,M") {
sm++;
(sms).emplace_back(i);
};
if (ss == "M,L") {
ml++;
(mls).emplace_back(i);
};
if (ss == "L,XL") {
lxl++;
(lxls).emplace_back(i);
};
if (ss == "XL,XXL") {
xlxxl++;
(xlxxls).emplace_back(i);
};
if (ss == "XXL,XXXL") {
xxlxxxl++;
(xxlxxxls).emplace_back(i);
};
}
for (auto i : sms) {
if (s > 0) {
s--;
r[i] = 1;
} else {
if (m > 0) {
m--;
r[i] = 2;
} else {
std::cout << "NO";
return 0;
}
}
};
for (auto i : mls) {
if (m > 0) {
m--;
r[i] = 2;
} else {
if (l > 0) {
l--;
r[i] = 3;
} else {
std::cout << "NO";
return 0;
}
}
};
for (auto i : lxls) {
if (l > 0) {
l--;
r[i] = 3;
} else {
if (xl > 0) {
xl--;
r[i] = 4;
} else {
std::cout << "NO";
return 0;
}
}
};
for (auto i : xlxxls) {
if (xl > 0) {
xl--;
r[i] = 4;
} else {
if (xxl > 0) {
xxl--;
r[i] = 5;
} else {
std::cout << "NO";
return 0;
}
}
};
for (auto i : xxlxxxls) {
if (xxl > 0) {
xxl--;
r[i] = 5;
} else {
if (xxxl > 0) {
xxxl--;
r[i] = 6;
} else {
std::cout << "NO";
return 0;
}
}
};
cout << "YES" << endl;
for (int i = 0; i < n; i++) {
switch (r[i]) {
case 1:
cout << "S" << endl;
break;
case 2:
cout << "M" << endl;
break;
case 3:
cout << "L" << endl;
break;
case 4:
cout << "XL" << endl;
break;
case 5:
cout << "XXL" << endl;
break;
case 6:
cout << "XXXL" << endl;
break;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int kosz[7];
int przyd[100001];
vector<int> t[6];
int main() {
for (int i = 1; i <= 6; i++) cin >> kosz[i];
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
bool przecinek = false;
int miej;
for (int j = 0; j < s.size(); j++) {
if (s[j] == ',') {
przecinek = true;
miej = j;
}
}
if (!przecinek) {
if (s.size() == 1) {
if (s[0] == 'S') {
kosz[1]--;
przyd[i] = 1;
}
if (s[0] == 'M') {
kosz[2]--;
przyd[i] = 2;
}
if (s[0] == 'L') {
kosz[3]--;
przyd[i] = 3;
}
} else {
kosz[s.size() + 2]--;
przyd[i] = s.size() + 2;
}
} else {
if (s[0] == 'S')
t[1].push_back(i);
else if (s[0] == 'M')
t[2].push_back(i);
else if (s[0] == 'L')
t[3].push_back(i);
else {
if (miej == 2) t[4].push_back(i);
if (miej == 3) t[5].push_back(i);
}
}
}
for (int i = 1; i <= 6; i++) {
if (kosz[i] < 0) {
cout << "NO";
return 0;
}
}
for (int i = 1; i <= 5; i++) {
for (int j = 0; j < t[i].size(); j++) {
if (kosz[i] > 0) {
kosz[i]--;
przyd[t[i][j]] = i;
} else {
kosz[i + 1]--;
przyd[t[i][j]] = i + 1;
}
}
}
for (int i = 1; i <= 6; i++) {
if (kosz[i] < 0) {
cout << "NO";
return 0;
}
}
cout << "YES" << endl;
for (int i = 1; i <= n; i++) {
if (przyd[i] == 1) cout << "S";
if (przyd[i] == 2) cout << "M";
if (przyd[i] == 3) cout << "L";
if (przyd[i] == 4) cout << "XL";
if (przyd[i] == 5) cout << "XXL";
if (przyd[i] == 6) cout << "XXXL";
if (i != n) cout << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
long long res = 1;
a = a % 1000000007;
while (b > 0) {
if (b & 1) {
res = (res * a) % 1000000007;
b--;
}
a = (a * a) % 1000000007;
b >>= 1;
}
return res;
}
long long fermat_inv(long long y) { return power(y, 1000000007 - 2ll); }
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) {
vector<int> ctr(6, 0);
for (int i = 0; i < 6; i++) cin >> ctr[i];
int check = 1;
string s[] = {"S", "M", "L", "XL", "XXL", "XXXL"};
vector<int> ctr1(5, 0);
int n;
cin >> n;
string ans[n];
vector<int> pos[5];
for (int i = 0; i < n; i++) {
string w;
cin >> w;
int found = 0;
for (int j = 0; j < 6 && !found; j++) {
if (s[j] == w) {
if (ctr[j] > 0) {
ctr[j]--;
ans[i] = w;
} else
check = 0;
found = 1;
}
}
for (int j = 0; j < 5 && !found; j++) {
string p = s[j] + "," + s[j + 1];
if (w == p) {
pos[j].push_back(i);
ctr1[j]++;
found = 1;
}
}
}
for (int j = 0; j < 5; j++) {
if (ctr1[j] <= ctr[j]) {
for (int i = 0; i < ctr1[j]; i++) {
ans[pos[j][i]] = s[j];
}
continue;
} else if (ctr1[j] - ctr[j] <= ctr[j + 1]) {
for (int i = 0; i < ctr[j]; i++) {
ans[pos[j][i]] = s[j];
}
for (int i = ctr[j]; i < ctr1[j]; i++) {
ans[pos[j][i]] = s[j + 1];
}
ctr[j + 1] -= ctr1[j] - ctr[j];
} else {
check = 0;
break;
}
}
if (check) {
cout << "YES\n";
for (int i = 0; i < n; i++) cout << ans[i] << "\n";
} else
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline void operator+=(pair<int, int> &a, pair<int, int> b) {
a.first += b.first;
a.second += b.second;
}
template <typename T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
const double eps = 1e-9;
const int MAXN = (int)2e5 + 256;
const int MOD = (int)1e9 + 7, INF = (int)1e9;
const long long INFLL = (long long)1e18;
int n, k;
struct edge {
long long v, u, cap, flow;
};
vector<int> g[MAXN];
vector<edge> e;
int ptr[MAXN], d[MAXN];
inline void addEdge(int v, int u, long long cap) {
e.push_back({v, u, cap, 0});
e.push_back({u, v, 0, 0});
g[v].push_back((int)e.size() - 2);
g[u].push_back((int)e.size() - 1);
}
inline bool bfs(int s, int t) {
queue<int> q;
q.push(s);
for (int i = 1; i <= t; ++i) d[i] = -1;
d[s] = 0;
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto id : g[v]) {
int to = e[id].u;
if (e[id].flow == e[id].cap) continue;
if (d[to] == -1) {
d[to] = d[v] + 1;
q.push(to);
}
}
}
return d[t] != -1;
}
long long dfs(int v, int t, long long push = INT_MAX) {
if (!push || v == t) return push;
for (int &id = ptr[v]; id < g[v].size(); ++id) {
int td = g[v][id];
int to = e[td].u;
if (e[td].flow == e[td].cap) continue;
if (d[to] != d[v] + 1) continue;
long long pushed = dfs(to, t, min(push, 1ll * e[td].cap - e[td].flow));
if (pushed) {
e[td].flow += pushed;
e[td ^ 1].flow -= pushed;
return pushed;
}
}
return 0;
}
inline long long DinitZ(int s, int t) {
long long res = 0;
while (bfs(s, t)) {
while (long long pushed = dfs(s, t)) res += pushed;
memset(ptr, 0, sizeof ptr);
}
return res;
}
int cnt[7];
inline int ggg(const string &s) {
if (s == "S") return 1;
if (s == "M") return 2;
if (s == "L") return 3;
if (s == "XL") return 4;
if (s == "XXL") return 5;
if (s == "XXXL") return 6;
}
inline string ttt(int s) {
if (s == 1) return "S";
if (s == 2) return "M";
if (s == 3) return "L";
if (s == 4) return "XL";
if (s == 5) return "XXL";
if (s == 6) return "XXXL";
}
vector<int> sss[MAXN];
int ans[MAXN];
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
for (int i = 1; i <= 6; ++i) cin >> cnt[i];
cin >> n;
vector<pair<int, pair<int, int> > > q;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
vector<int> v;
string t;
for (int i = 0; i < s.size(); ++i) {
if (isalpha(s[i]))
t += s[i];
else {
v.push_back(ggg(t));
t = "";
}
}
v.push_back(ggg(t));
if (v.size() == 1) {
cnt[v[0]]--;
} else {
q.push_back(make_pair(i, make_pair(v[0], v[1])));
}
sss[i] = v;
}
for (int i = 1; i <= 6; ++i)
if (cnt[i] < 0) cout << "NO", exit(0);
int ss = n + 6 + 1, tt = n + 6 + 2;
for (int i = 1; i <= 6; ++i) {
addEdge(ss, i, cnt[i]);
}
for (auto it : q) {
addEdge(it.second.first, 6 + it.first + 1, 1);
addEdge(it.second.second, 6 + it.first + 1, 1);
}
for (int i = 1; i <= n; ++i) addEdge(6 + i, tt, 1);
int x = DinitZ(ss, tt);
if (x == q.size()) {
for (auto it : e) {
if (it.flow == 1 && it.cap == 1 && 1 <= it.v && it.v <= 6) {
ans[it.u - 6] = it.v;
}
}
cout << "YES\n";
for (int i = 0; i < n; ++i) {
if (sss[i].size() == 1) {
cout << ttt(sss[i][0]) << '\n';
} else {
cout << ttt(ans[i + 1]) << '\n';
}
}
} else {
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
vector<string> split(string s, string sep) {
string act = "";
vector<string> res;
for (int c = 0; c < s.size(); c++) {
bool split = false;
for (int c2 = 0; c2 < sep.size(); c2++) {
if (sep[c2] == s[c]) {
split = true;
break;
}
}
if (split) {
res.push_back(act);
act = "";
} else {
act = act + s[c];
}
}
res.push_back(act);
return res;
}
string removeChars(string s, string filters) {
string res = "";
for (int c = 0; c < s.size(); c++) {
bool fine = true;
for (int c2 = 0; c2 < filters.size(); c2++) {
if (filters[c2] == s[c]) {
fine = false;
break;
}
}
if (fine) res = res + s[c];
}
return res;
}
string replaceChars(string s, string from, string to) {
for (int c = 0; c < s.size(); c++) {
for (int c2 = 0; c2 < from.size(); c2++) {
if (from[c2] == s[c]) {
s[c] = to[c2 % to.size()];
break;
}
}
}
return s;
}
struct MaximumFlow {
static const int InfCapacity = INF;
struct Edge {
int to;
int capacity;
int rev;
};
vector<vector<Edge> > g;
void init(int n) { g.assign(n, vector<Edge>()); }
void add(int i, int j, int capacity) {
Edge e, f;
e.to = j, f.to = i;
e.capacity = capacity, f.capacity = 0;
g[i].push_back(e);
g[j].push_back(f);
g[i].back().rev = (int)g[j].size() - 1;
g[j].back().rev = (int)g[i].size() - 1;
}
void addB(int i, int j, int capacity) {
Edge e, f;
e.to = j, f.to = i;
e.capacity = capacity, f.capacity = capacity;
g[i].push_back(e);
g[j].push_back(f);
g[i].back().rev = (int)g[j].size() - 1;
g[j].back().rev = (int)g[i].size() - 1;
}
int maximumFlow(int s, int t) {
int n = g.size();
vector<int> level(n);
int total = 0;
bool update;
do {
update = false;
fill(level.begin(), level.end(), -1);
level[s] = 0;
queue<int> q;
q.push(s);
for (int d = n; !q.empty() && level[q.front()] < d;) {
int u = q.front();
q.pop();
if (u == t) d = level[u];
for (auto e = (g[u]).begin(); e != (g[u]).end(); ++e)
if (e->capacity > 0 && level[e->to] == -1)
q.push(e->to), level[e->to] = level[u] + 1;
}
vector<int> iter(n);
for (int i = 0; i < n; i++) iter[i] = (int)g[i].size() - 1;
while (1) {
int f = augment(level, iter, s, t, InfCapacity);
if (f == 0) break;
total += f;
update = true;
}
} while (update);
return total;
}
int augment(vector<int> &level, vector<int> &iter, int u, int t, int f) {
if (u == t || f == 0) return f;
int lv = level[u];
if (lv == -1) return 0;
level[u] = -1;
for (; iter[u] >= 0; --iter[u]) {
Edge &e = g[u][iter[u]];
if (level[e.to] <= lv) continue;
int l = augment(level, iter, e.to, t, min(f, e.capacity));
if (l == 0) continue;
e.capacity -= l;
g[e.to][e.rev].capacity += l;
level[u] = lv;
return l;
}
return 0;
}
};
int main() {
vector<int> sizes(6);
for (int c = 0; c < sizes.size(); c++) cin >> sizes[c];
int n;
cin >> n;
MaximumFlow m;
m.init(n + 6 + 2);
for (int c = 0; c < 6; c++) {
m.add(c + 2, 1, sizes[c]);
}
string poss[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
for (int c = 0; c < n; c++) {
m.add(0, 8 + c, 1);
string line;
cin >> line;
vector<string> possibilities = split(line, ",");
for (int c2 = 0; c2 < possibilities.size(); c2++) {
for (int c3 = 0; c3 < 6; c3++) {
if (poss[c3] == possibilities[c2]) {
m.add(8 + c, c3 + 2, 1);
}
}
}
}
int res = m.maximumFlow(0, 1);
if (res != n) {
cout << "NO";
return 0;
}
cout << "YES" << endl;
for (int c = 0; c < n; c++) {
for (int c2 = 0; c2 < m.g[8 + c].size(); c2++) {
if (m.g[8 + c][c2].capacity == 0) {
cout << poss[m.g[8 + c][c2].to - 2] << endl;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a(6);
vector<vector<int>> b(5, vector<int>());
vector<string> nta(6);
vector<int> inp;
map<string, int> atn;
nta[0] = "S";
nta[1] = "M";
nta[2] = "L";
nta[3] = "XL";
nta[4] = "XXL";
nta[5] = "XXXL";
atn["S"] = 1;
atn["M"] = 2;
atn["L"] = 3;
atn["XL"] = 4;
atn["XXL"] = 5;
atn["XXXL"] = 6;
for (int i = 0; i < 6; i++) cin >> a[i];
int n;
cin >> n;
vector<string> ans(n, "");
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (atn[s] != 0) {
a[atn[s] - 1]--;
ans[i] = s;
inp.push_back(atn[s] - 1);
if (a[atn[s] - 1] < 0) {
cout << "NO";
exit(0);
}
} else {
int sp = s.find(',');
string f = s.substr(0, sp);
b[atn[f] - 1].push_back(i);
inp.push_back(atn[s] - 1);
}
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < b[i].size(); j++) {
if (a[i] > 0) {
a[i]--;
ans[b[i][j]] = nta[i];
} else if (a[i + 1] > 0) {
a[i + 1]--;
ans[b[i][j]] = nta[i + 1];
} else {
cout << "NO";
exit(0);
}
}
}
cout << "YES\n";
for (int i = 0; i < n; i++) cout << ans[i] << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int maxm = 1005;
const int inf = INT_MAX;
int n;
int r[10];
struct N {
int s;
bool c;
int no;
int ans;
bool operator<(const N &b) const {
if (this->s < b.s) return true;
if (this->s == b.s) {
if (this->c != b.c)
return !this->c;
else
return this->no < b.no;
}
return false;
}
};
bool comp(const N &a, const N &b) { return a.no < b.no; }
N a[maxn];
int ans[maxn];
int main() {
for (int i = 1; i <= 6; i++) scanf("%d", &r[i]);
scanf("%d", &n);
for (int i = 0; i < n; i++) {
char str[10];
scanf("%s", str);
int l;
l = strlen(str);
if (l == 8) {
a[i].s = 5;
a[i].c = true;
} else if (l == 6) {
a[i].s = 4;
a[i].c = true;
} else if (l == 4) {
if (str[1] == ',') {
a[i].s = 3;
a[i].c = true;
} else {
a[i].s = 6;
a[i].c = false;
}
} else if (l == 3) {
if (str[0] == 'X') {
a[i].s = 5;
a[i].c = false;
} else {
if (str[0] == 'S') a[i].s = 1;
if (str[0] == 'M') a[i].s = 2;
a[i].c = true;
}
} else if (l == 2) {
a[i].s = 4;
a[i].c = false;
} else {
if (str[0] == 'S')
a[i].s = 1;
else if (str[0] == 'M')
a[i].s = 2;
else
a[i].s = 3;
a[i].c = false;
}
a[i].no = i;
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (r[a[i].s] <= 0) {
if (a[i].c) {
if (r[a[i].s + 1] <= 0) {
printf("NO\n");
return 0;
} else {
r[a[i].s + 1]--;
a[i].ans = a[i].s + 1;
}
} else {
printf("NO\n");
return 0;
}
} else {
r[a[i].s]--;
a[i].ans = a[i].s;
}
}
sort(a, a + n, comp);
printf("YES\n");
for (int i = 0; i < n; i++) {
if (a[i].ans == 1) printf("S\n");
if (a[i].ans == 2) printf("M\n");
if (a[i].ans == 3) printf("L\n");
if (a[i].ans == 4) printf("XL\n");
if (a[i].ans == 5) printf("XXL\n");
if (a[i].ans == 6) printf("XXXL\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > V;
int rem[10], ans[100005];
int main() {
int main_flag = 1;
scanf("%d%d%d%d%d%d", &rem[1], &rem[2], &rem[3], &rem[4], &rem[5], &rem[6]);
map<string, int> M;
M["S"] = 1;
M["M"] = 2;
M["L"] = 3;
M["XL"] = 4;
M["XXL"] = 5;
M["XXXL"] = 6;
int N;
scanf("%d", &N);
int i, j;
for (i = 1; i <= N; i++) {
string S;
cin >> S;
int seperator, flag = 0;
for (j = 0; j < S.size(); j++) {
if (S[j] == ',') {
seperator = j;
flag = 1;
break;
}
}
if (flag == 0) {
rem[M[S]]--;
ans[i] = M[S];
if (rem[M[S]] < 0) main_flag = 0;
continue;
}
string S1, S2;
S1 = S.substr(0, seperator);
S2 = S.substr(j + 1, S.size() - 1 - seperator);
V.push_back(make_pair(make_pair(M[S1], M[S2]), i));
}
sort(V.begin(), V.end());
for (i = 0; i < V.size(); i++) {
int t1 = V[i].first.first;
int t2 = V[i].first.second;
if (rem[t1] > 0) {
ans[V[i].second] = t1;
rem[t1]--;
if (rem[t1] < 0) {
main_flag = 0;
break;
}
continue;
} else {
ans[V[i].second] = t2;
rem[t2]--;
if (rem[t2] < 0) {
main_flag = 0;
break;
}
}
}
if (main_flag == 0) {
printf("NO\n");
return 0;
}
printf("YES\n");
for (i = 1; i <= N; i++) {
if (ans[i] == 1) printf("S\n");
if (ans[i] == 2) printf("M\n");
if (ans[i] == 3) printf("L\n");
if (ans[i] == 4) printf("XL\n");
if (ans[i] == 5) printf("XXL\n");
if (ans[i] == 6) printf("XXXL\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
vector<long long> c(6);
for (long long i = 0; i < 6; i++) cin >> c[i];
vector<string> a = {"S", "M", "L", "XL", "XXL", "XXXL"};
long long ans = 0;
vector<pair<long long, long long> > z;
long long n;
cin >> n;
vector<long long> answer(n);
for (long long k = 0; k < n; k++) {
string s;
cin >> s;
string tmp = "", tmp2 = "";
for (long long i = 0; i < s.size(); i++)
if (s[i] == ',') {
for (long long j = 0; j < i; j++) tmp += s[j];
for (long long j = i + 1; j < s.size(); j++) tmp2 += s[j];
}
if (tmp.size() == 0) {
for (long long i = 0; i < 6; i++) {
if (s == a[i] && c[i] > 0) {
ans++, c[i]--;
answer[k] = i;
}
}
} else {
long long x = -1, y = -1;
for (long long i = 0; i < 6; i++)
if (tmp == a[i]) x = i;
for (long long i = 0; i < 6; i++)
if (tmp2 == a[i]) y = i;
z.push_back({x, k});
}
}
sort((z).begin(), (z).end());
for (auto el : z) {
long long x = el.first, y = el.second;
if (c[x] > 0) {
c[x]--, ans++;
answer[y] = x;
} else if (c[x + 1] > 0) {
c[x + 1]--, ans++;
answer[y] = x + 1;
}
}
if (ans != n) {
cout << "NO";
return 0;
}
cout << "YES\n";
for (long long i = 0; i < n; i++) cout << a[answer[i]] << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAX = 1e14 + 8;
const long long MAXN = 1e5 + 8;
const long long eps = 1e-4;
using namespace std;
long long a[15];
long long siz(string s) {
if (s == "S") return 0;
if (s == "M") return 1;
if (s == "L") return 2;
if (s == "XL") return 3;
if (s == "XXL") return 4;
if (s == "XXXL") return 5;
}
string rsiz(long long s) {
if (s == 0) return "S";
if (s == 1) return "M";
if (s == 2) return "L";
if (s == 3) return "XL";
if (s == 4) return "XXL";
if (s == 5) return "XXXL";
}
vector<pair<pair<short int, long long>, long long> > p;
string rs[100003];
int main() {
for (int i = 0; i < 6; i++) {
cin >> a[i];
}
long long n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
char cc[55];
scanf("%s", &cc);
s = cc;
string s1 = "", s2 = "";
int j = 0;
for (; j < s.size(); j++) {
if (s[j] != ',')
s1 += s[j];
else
break;
}
for (; j < s.size(); j++) {
if (s[j] != ',') s2 += s[j];
}
long long x = siz(s1);
if (s2 == "") {
if (a[x] == 0) {
cout << "NO";
return 0;
}
rs[i] = s1;
a[x]--;
continue;
}
long long y = siz(s2);
if (x > y) swap(x, y);
p.push_back({{x, y}, i});
}
sort(p.begin(), p.end());
for (int i = 0; i < p.size(); i++) {
long long x = p[i].first.first;
long long y = p[i].first.second;
long long ind = p[i].second;
if (a[x] > 0) {
rs[ind] = rsiz(x);
a[x]--;
continue;
}
if (a[y] > 0) {
rs[ind] = rsiz(y);
a[y]--;
continue;
}
cout << "NO";
return 0;
}
cout << "YES\n";
for (int i = 0; i < n; i++) {
cout << rs[i] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int u, v;
long long cap, flow;
Edge() {}
Edge(int u, int v, long long cap) : u(u), v(v), cap(cap), flow(0) {}
};
struct Dinic {
int N;
vector<Edge> E;
vector<vector<int>> g;
vector<int> d, pt;
Dinic(int N) : N(N), E(0), g(N), d(N), pt(N) {}
void AddEdge(int u, int v, long long cap) {
if (u != v) {
E.emplace_back(u, v, cap);
g[u].emplace_back(E.size() - 1);
E.emplace_back(v, u, 0);
g[v].emplace_back(E.size() - 1);
}
}
bool BFS(int S, int T) {
queue<int> q({S});
fill(d.begin(), d.end(), N + 1);
d[S] = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
if (u == T) break;
for (int k : g[u]) {
Edge &e = E[k];
if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {
d[e.v] = d[e.u] + 1;
q.emplace(e.v);
}
}
}
return d[T] != N + 1;
}
long long DFS(int u, int T, long long flow = -1) {
if (u == T || flow == 0) return flow;
for (int &i = pt[u]; i < g[u].size(); ++i) {
Edge &e = E[g[u][i]];
Edge &oe = E[g[u][i] ^ 1];
if (d[e.v] == d[e.u] + 1) {
long long amt = e.cap - e.flow;
if (flow != -1 && amt > flow) amt = flow;
if (long long pushed = DFS(e.v, T, amt)) {
e.flow += pushed;
oe.flow -= pushed;
return pushed;
}
}
}
return 0;
}
long long MaxFlow(int S, int T) {
long long total = 0;
while (BFS(S, T)) {
fill(pt.begin(), pt.end(), 0);
while (long long flow = DFS(S, T)) total += flow;
}
return total;
}
};
const int maxn = 60, maxm = 510;
int main() {
unordered_map<string, int> id(
{{"S", 0}, {"M", 1}, {"L", 2}, {"XL", 3}, {"XXL", 4}, {"XXXL", 5}});
char shirts[][100] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int cnt[6] = {0}, pn;
for (int i = 0; i < 6; i++) cin >> cnt[i];
scanf("%d\n", &pn);
int s = pn + 6, t = pn + 7;
Dinic di(6 + pn + 2);
for (int i = 0; i < 6; i++) di.AddEdge(s, i, cnt[i]);
for (int i = 1; i <= pn; i++) {
char ln[100], *tok;
scanf("%s", ln);
tok = strtok(ln, ",");
int u = id[string(tok)];
di.AddEdge(u, i + 5, 1);
tok = strtok(NULL, ",");
if (tok == NULL) continue;
u = id[string(tok)];
di.AddEdge(u, i + 5, 1);
}
for (int i = 1; i <= pn; i++) di.AddEdge(i + 5, t, 1);
long long mf = di.MaxFlow(s, t);
if (mf < pn) {
cout << "NO";
return 0;
}
cout << "YES\n";
int tsh[pn + 1];
for (int u = 0; u < 6; u++) {
for (auto v : di.g[u]) {
Edge &e = di.E[v];
if (e.v > 5 && e.v <= 5 + pn && e.cap && e.flow) tsh[e.v - 5] = e.u;
}
}
for (int i = 1; i <= pn; i++) cout << shirts[tsh[i]] << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
long long powmod(long long a, long long b) {
long long res = 1;
if (a >= mod) a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a;
if (res >= mod) res %= mod;
a = a * a;
if (a >= mod) a %= mod;
}
return res;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int lef[17], sum[17];
int sing[17], com[17];
int t[17][17];
int x[100000 + 5], y[100000 + 5];
string ss[10] = {"S", "M", "L", "XL", "XXL", "XXXL"};
void p(int x) { cout << ss[x - 1] << '\n'; }
int main() {
ios_base::sync_with_stdio(false);
;
cin.tie(0);
cout.tie(0);
string s;
int i, j, n, typ;
for (i = 1; i <= 6; i++) {
cin >> lef[i];
}
cin >> n;
for (i = 1; i <= n; i++) {
cin >> s;
for (j = 0; j < s.length(); j++) {
if (s[j] == ',') break;
}
if (s[0] == 'S')
typ = 1;
else if (s[0] == 'M')
typ = 2;
else if (s[0] == 'L')
typ = 3;
else if (s[1] == 'L')
typ = 4;
else if (s[2] == 'L')
typ = 5;
else if (s[3] == 'L')
typ = 6;
if (j == s.length()) {
sing[typ]++;
x[i] = 1;
y[i] = typ;
} else {
com[typ]++;
x[i] = 2;
y[i] = typ;
}
}
i = 1;
while (i < 7) {
if ((i > 1) && com[i - 1]) {
lef[i] -= com[i - 1];
t[i][i - 1] += com[i - 1];
com[i - 1] = 0;
if (lef[i] < 0) {
cout << "NO\n";
return 0;
}
}
lef[i] -= sing[i];
if (lef[i] < 0) {
cout << "NO\n";
return 0;
}
int v = min(lef[i], com[i]);
t[i][i + 1] += min(lef[i], com[i]);
lef[i] -= min(lef[i], com[i]);
com[i] -= v;
i++;
}
cout << "YES\n";
for (i = 1; i <= n; i++) {
if (x[i] == 1)
p(y[i]);
else if (t[y[i]][y[i] + 1]) {
t[y[i]][y[i] + 1]--;
p(y[i]);
} else {
t[y[i] + 1][y[i]]--;
p(y[i] + 1);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct flow_graph {
int MAX_V, E, s, t, head, tail;
int *cap, *to, *next, *last, *dist, *q, *now;
flow_graph() {}
flow_graph(int V, int MAX_E) {
MAX_V = V;
E = 0;
cap = new int[2 * MAX_E], to = new int[2 * MAX_E],
next = new int[2 * MAX_E];
last = new int[MAX_V], q = new int[MAX_V], dist = new int[MAX_V],
now = new int[MAX_V];
fill(last, last + MAX_V, -1);
}
void clear() {
fill(last, last + MAX_V, -1);
E = 0;
}
void add_edge(int u, int v, int uv, int vu = 0) {
to[E] = v, cap[E] = uv, next[E] = last[u];
last[u] = E++;
to[E] = u, cap[E] = vu, next[E] = last[v];
last[v] = E++;
}
bool bfs() {
fill(dist, dist + MAX_V, -1);
head = tail = 0;
q[tail] = t;
++tail;
dist[t] = 0;
while (head < tail) {
int v = q[head];
++head;
for (int e = last[v]; e != -1; e = next[e]) {
if (cap[e ^ 1] > 0 && dist[to[e]] == -1) {
q[tail] = to[e];
++tail;
dist[to[e]] = dist[v] + 1;
}
}
}
return dist[s] != -1;
}
int dfs(int v, int f) {
if (v == t) return f;
for (int &e = now[v]; e != -1; e = next[e]) {
if (cap[e] > 0 && dist[to[e]] == dist[v] - 1) {
int ret = dfs(to[e], min(f, cap[e]));
if (ret > 0) {
cap[e] -= ret;
cap[e ^ 1] += ret;
return ret;
}
}
}
return 0;
}
long long max_flow(int source, int sink) {
s = source;
t = sink;
long long f = 0;
int x;
while (bfs()) {
for (int i = 0; i < MAX_V; ++i) now[i] = last[i];
while (true) {
x = dfs(s, INT_MAX);
if (x == 0) break;
f += x;
}
}
return f;
}
};
int w[7], npv[40];
vector<int> mopper;
vector<pair<pair<int, int>, int> > vs;
vector<string> sol[40];
int main() {
int V, E, u, v, c;
map<string, int> has;
map<int, string> rhas;
string tmp;
has["S"] = 1;
has["M"] = 2;
has["L"] = 3;
has["XL"] = 4;
has["XXL"] = 5;
has["XXXL"] = 6;
rhas[1] = "S";
rhas[2] = "M";
rhas[3] = "L";
rhas[4] = "XL";
rhas[5] = "XXL";
rhas[6] = "XXXL";
for (int i = 1; i <= 6; i++) {
cin >> w[i];
}
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string tmp, a, b;
cin >> tmp;
int coun = 0;
for (int j = 0; j < tmp.size(); j++) {
if (tmp[j] == ',') {
coun++;
} else if (coun == 0) {
a.push_back(tmp[j]);
} else
b.push_back(tmp[j]);
}
if (coun == 0) {
npv[has[a]]++;
mopper.push_back(has[a]);
} else {
if (has[a] > has[b]) swap(a, b);
npv[has[a] * 6 + has[b]]++;
mopper.push_back(has[a] * 6 + has[b]);
}
}
for (int i = 0; i < n; i++) {
}
for (int i = 1; i <= 6; i++) {
vs.push_back(make_pair(make_pair(0, i), w[i]));
}
for (int i = 1; i <= 6; i++) {
vs.push_back(make_pair(make_pair(i, i + 6), w[i]));
vs.push_back(make_pair(make_pair(i + 6, 59), npv[i]));
}
for (int i = 1; i <= 6; i++) {
for (int j = i + 1; j <= 6; j++) {
vs.push_back(make_pair(make_pair(i, i * 6 + j + 6), w[i]));
vs.push_back(make_pair(make_pair(j, i * 6 + j + 6), w[j]));
}
}
for (int i = 1; i <= 6; i++) {
for (int j = i + 1; j <= 6; j++) {
vs.push_back(make_pair(make_pair(i * 6 + j + 6, 59), npv[i * 6 + j]));
}
}
flow_graph G(100, vs.size() + 1), G2(100, vs.size() + 1);
for (int i = 0; i < vs.size(); i++) {
if (vs[i].second) {
G.add_edge(vs[i].first.first, vs[i].first.second, vs[i].second, 0);
G2.add_edge(vs[i].first.first, vs[i].first.second, vs[i].second, 0);
}
}
int ff = G.max_flow(0, 59), sumd = 0;
if (ff >= n) {
cout << "YES\n";
for (int i = 0; i < G.E; i += 2) {
int u = G.to[i], v = G.to[i + 1];
swap(u, v);
if (u >= 1 && u <= 6 && v >= 7 && v <= 42) {
int del = G2.cap[i] - G.cap[i];
sumd += del;
while (del >= 1) {
sol[v - 6].push_back(rhas[u]);
w[u]--;
if (w[u] < 0) {
cout << "fucking failed: " << v - 6 << " " << del << endl;
}
del--;
}
}
}
for (int i = 0; i < n; i++) {
cout << sol[mopper[i]].back() << endl;
sol[mopper[i]].pop_back();
}
} else
cout << "NO\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int S, M, L, XL, XXL, XXXL;
int n;
int SM, ML, LXL, XLXXL, XXLXXXL;
vector<string> vec;
int main() {
cin >> S >> M >> L >> XL >> XXL >> XXXL;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
vec.push_back(s);
if (s == "S") S--;
if (s == "M") M--;
if (s == "L") L--;
if (s == "XL") XL--;
if (s == "XXL") XXL--;
if (s == "XXXL") XXXL--;
if (s.substr(0, 2) == "S,") SM++;
if (s.substr(0, 2) == "M,") ML++;
if (s.substr(0, 2) == "L,") LXL++;
if (s.substr(0, 3) == "XL,") XLXXL++;
if (s.substr(0, 4) == "XXL,") XXLXXXL++;
}
if (S < 0 || M < 0 || L < 0 || XL < 0 || XXL < 0 || XXXL < 0) {
cout << "NO" << endl;
return 0;
}
int a = min(S, SM);
S -= a;
SM -= a;
M -= SM;
if (M < 0) {
cout << "NO" << endl;
return 0;
}
int b = min(M, ML);
M -= b;
ML -= b;
L -= ML;
if (L < 0) {
cout << "NO" << endl;
return 0;
}
int c = min(L, LXL);
L -= c;
LXL -= c;
XL -= LXL;
if (XL < 0) {
cout << "NO" << endl;
return 0;
}
int d = min(XL, XLXXL);
XL -= d;
XLXXL -= d;
XXL -= XLXXL;
if (XXL < 0) {
cout << "NO" << endl;
return 0;
}
int e = min(XXL, XXLXXXL);
XXL -= e;
XXLXXXL -= e;
XXXL -= XXLXXXL;
if (XXXL < 0) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
for (auto s : vec) {
if (s == "S") cout << "S" << endl;
if (s == "M") cout << "M" << endl;
if (s == "L") cout << "L" << endl;
if (s == "XL") cout << "XL" << endl;
if (s == "XXL") cout << "XXL" << endl;
if (s == "XXXL") cout << "XXXL" << endl;
if (s.substr(0, 2) == "S,") {
if (a > 0) {
cout << "S" << endl;
a--;
} else
cout << "M" << endl;
}
if (s.substr(0, 2) == "M,") {
if (b > 0) {
cout << "M" << endl;
b--;
} else
cout << "L" << endl;
}
if (s.substr(0, 2) == "L,") {
if (c > 0) {
cout << "L" << endl;
c--;
} else
cout << "XL" << endl;
}
if (s.substr(0, 3) == "XL,") {
if (d > 0) {
cout << "XL" << endl;
d--;
} else
cout << "XXL" << endl;
}
if (s.substr(0, 4) == "XXL,") {
if (e > 0) {
cout << "XXL" << endl;
e--;
} else
cout << "XXXL" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int rec[maxn];
int v[maxn];
int main() {
ios::sync_with_stdio(false);
for (int i = 0; i < 6; i++) {
cin >> v[i];
}
int n;
cin >> n;
vector<pair<int, int> > mult;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s == "S") {
rec[i] = 0;
v[0]--;
} else if (s == "M") {
rec[i] = 1;
v[1]--;
} else if (s == "L") {
rec[i] = 2;
v[2]--;
} else if (s == "XL") {
rec[i] = 3;
v[3]--;
} else if (s == "XXL") {
rec[i] = 4;
v[4]--;
} else if (s == "XXXL") {
rec[i] = 5;
v[5]--;
} else {
if (s[0] == 'S') {
mult.push_back(make_pair(0, i));
} else if (s[0] == 'M') {
mult.push_back(make_pair(1, i));
} else if (s[0] == 'L') {
mult.push_back(make_pair(2, i));
} else if (s[1] == 'L') {
mult.push_back(make_pair(3, i));
} else if (s[2] == 'L') {
mult.push_back(make_pair(4, i));
} else if (s[3] == 'L') {
mult.push_back(make_pair(5, i));
}
}
}
sort(mult.begin(), mult.end());
for (int i = 0; i < mult.size(); i++) {
if (v[mult[i].first]) {
rec[mult[i].second] = mult[i].first;
v[mult[i].first]--;
} else if (v[mult[i].first + 1]) {
rec[mult[i].second] = mult[i].first + 1;
v[mult[i].first + 1]--;
} else {
cout << "NO" << endl;
return 0;
}
}
for (int i = 0; i < 6; i++) {
if (v[i] < 0) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
for (int i = 0; i < n; i++) {
if (rec[i] == 0) {
cout << "S" << endl;
} else if (rec[i] == 1) {
cout << "M" << endl;
} else if (rec[i] == 2) {
cout << "L" << endl;
} else if (rec[i] == 3) {
cout << "XL" << endl;
} else if (rec[i] == 4) {
cout << "XXL" << endl;
} else if (rec[i] == 5) {
cout << "XXXL" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int num[8], p[100005];
struct node {
int x, t;
} a[100005];
char names[6][6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int ff(char *s) {
if (s[0] == 'S') return 0;
if (s[0] == 'M') return 1;
if (s[0] == 'L') return 2;
if (s[1] == 'L') return 3;
if (s[2] == 'L') return 4;
if (s[3] == 'L') return 5;
}
bool cmp(node a, node b) { return b.x > a.x; }
int slove(int cnt) {
sort(a, a + cnt, cmp);
for (int i = 0; i < cnt; i++) {
if (num[a[i].x]) {
num[a[i].x]--;
p[a[i].t] = a[i].x;
} else if (num[a[i].x + 1]) {
num[a[i].x + 1]--;
p[a[i].t] = a[i].x + 1;
} else
return 0;
}
return 1;
}
int main() {
int sum = 0, n;
char name[7][11];
for (int i = 0; i < 6; i++) {
scanf("%d", &num[i]);
sum += num[i];
}
scanf("%d", &n);
int cnt = 0;
char str[11], str1[11], str2[11];
for (int i = 0; i < n; i++) {
scanf("%s", str);
int j, k;
for (j = 0; str[j] != ',' && str[j]; j++) str1[j] = str[j];
str1[j] = '\0';
if (j == strlen(str)) {
int ss = ff(str1);
p[i] = ss;
num[ss]--;
} else {
for (k = j + 1; str[k]; k++) str2[k - j - 1] = str[k];
str2[k - j - 1] = '\0';
a[cnt].x = min(ff(str1), ff(str2));
a[cnt++].t = i;
}
}
if (sum < n) {
printf("NO\n");
return 0;
}
int gg = slove(cnt);
for (int i = 0; i < 6; i++)
if (num[i] < 0) gg = 0;
if (!gg)
printf("NO\n");
else {
printf("YES\n");
for (int i = 0; i < n; i++) printf("%s\n", names[p[i]]);
}
}
|
#include <bits/stdc++.h>
using namespace std;
void split(const string& s, char delim, vector<string>& elems) {
stringstream ss;
ss.str(s);
string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
}
vector<string> split(const string& s, char delim) {
vector<string> elems;
split(s, delim, elems);
return elems;
}
int main() {
vector<int> num(6);
for (int i = 0; i < num.size(); i++) {
cin >> num[i];
}
int n;
cin >> n;
map<string, int> data;
data["S"] = 0;
data["M"] = 1;
data["L"] = 2;
data["XL"] = 3;
data["XXL"] = 4;
data["XXXL"] = 5;
map<int, string> data1;
data1[0] = "S";
data1[1] = "M";
data1[2] = "L";
data1[3] = "XL";
data1[4] = "XXL";
data1[5] = "XXXL";
vector<int> multi(n, -1);
vector<int> single(n, -1);
vector<int> value(n, -1);
for (int i = 0; i < n; i++) {
string temp;
cin >> temp;
size_t found = temp.find(',');
if (found != std::string::npos) {
vector<string> arb = split(temp, ',');
if (data[arb[0]] < data[arb[1]])
multi[i] = data[arb[0]];
else
multi[i] = data[arb[1]];
} else {
single[i] = data[temp];
}
}
for (int i = 0; i < n; i++) {
if (single[i] != -1 and value[i] == -1) {
num[single[i]]--;
value[i] = single[i];
}
}
bool pos = true;
for (int i = 0; i < 6; i++) {
if (num[i] < 0) {
pos = false;
break;
}
}
if (pos) {
for (int i = 0; i < n; i++) {
if (num[0] > 0) {
if (multi[i] == 0 and value[i] == -1) {
num[0]--;
value[i] = 0;
}
} else
break;
}
for (int i = 0; i < n; i++) {
if (num[5] > 0) {
if (multi[i] == 4 and value[i] == -1) {
num[5]--;
value[i] = 5;
}
} else
break;
}
for (int i = 0; i < n; i++) {
if (num[1] > 0) {
if (multi[i] == 0 and value[i] == -1) {
num[1]--;
value[i] = 1;
}
} else
break;
}
for (int i = 0; i < n; i++) {
if (num[4] > 0) {
if (multi[i] == 4 and value[i] == -1) {
num[4]--;
value[i] = 4;
}
} else
break;
}
for (int i = 0; i < n; i++) {
if (num[1] > 0) {
if (multi[i] == 1 and value[i] == -1) {
num[1]--;
value[i] = 1;
}
} else
break;
}
for (int i = 0; i < n; i++) {
if (num[4] > 0) {
if (multi[i] == 3 and value[i] == -1) {
num[4]--;
value[i] = 4;
}
} else
break;
}
for (int i = 0; i < n; i++) {
if (num[2] > 0) {
if (multi[i] == 1 and value[i] == -1) {
num[2]--;
value[i] = 2;
}
} else
break;
}
for (int i = 0; i < n; i++) {
if (num[3] > 0) {
if (multi[i] == 3 and value[i] == -1) {
num[3]--;
value[i] = 3;
}
} else
break;
}
for (int i = 0; i < n; i++) {
if (num[2] > 0) {
if (multi[i] == 2 and value[i] == -1) {
num[2]--;
value[i] = 2;
}
} else
break;
}
for (int i = 0; i < n; i++) {
if (num[3] > 0) {
if (multi[i] == 2 and value[i] == -1) {
num[3]--;
value[i] = 3;
}
} else
break;
}
for (int i = 0; i < value.size(); i++) {
if (value[i] == -1) {
pos = false;
break;
}
}
}
if (!pos)
cout << "NO" << endl;
else {
cout << "YES" << endl;
for (int i = 0; i < value.size(); i++) {
cout << data1[value[i]] << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long MX = 9999999999;
long long n, m, l, t, k, e, fre = 0, c, total, nnn, yes, mx, mn = -1, r, xx, yy,
zz;
long long a[10];
string ss[] = {"S", "M", "L", "XL", "XXL", "XXXL"};
map<string, long long> num;
map<string, long long> wo, wow;
map<string, long long> koyta;
vector<string> all, check;
void dekhao() {
cout << endl;
for (int i = 0; i < 6; i++) {
cout << num[ss[i]] << " ";
}
cout << endl;
for (int i = 0; i < 5; i++) {
cout << wo[ss[i]] << " ";
}
cout << endl;
}
void abardekhao() {
cout << endl;
for (int i = 0; i < 5; i++) {
cout << koyta[ss[i]] << " ";
}
cout << endl;
}
int main() {
for (int i = 0; i < 6; i++) {
cin >> a[0];
num[ss[i]] = a[0];
}
cin >> n;
string second;
for (int i = 0; i < n; i++) {
cin >> second;
all.push_back(second);
if (second.find(',') == second.npos) {
num[second]--;
if (num[second] < 0) {
cout << "NO" << endl;
return 0;
}
} else {
string o = second.substr(0, second.find(','));
string p = second.substr(second.find(',') + 1, second.size());
wo[o]++;
}
}
for (int i = 0; i < 5; i++) {
if (num[ss[i]] + num[ss[i + 1]] < wo[ss[i]]) {
cout << "NO" << endl;
return 0;
} else {
a[0] = min(num[ss[i]], wo[ss[i]]);
koyta[ss[i] + "," + ss[i + 1]] = a[0];
wo[ss[i]] -= a[0];
num[ss[i + 1]] -= wo[ss[i]];
}
}
cout << "YES" << endl;
for (int i = 0; i < n; i++) {
string w = all[i];
if (w.find(',') == w.npos) {
cout << w << endl;
} else {
string ag = w.substr(0, w.find(','));
if (koyta[w] > 0) {
koyta[w]--;
cout << ag << endl;
} else {
cout << w.substr(w.find(',') + 1, w.size()) << endl;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int N = 1000000 + 10;
const int M = 1000;
const string st2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string s1 = "abcdefghijklmnopqrstuvwxyz";
pair<int, int> a[N];
int b[N];
string ans[N], da[N];
int main() {
cin >> b[1] >> b[2] >> b[3] >> b[4] >> b[5] >> b[6];
int n;
cin >> n;
da[1] = "S";
da[2] = "M";
da[3] = "L";
da[4] = "XL";
da[5] = "XXL";
da[6] = "XXXL";
for (int i = 1; i <= n; i++) {
string second;
cin >> second;
if (second == "S")
a[i] = make_pair(1, 0);
else if (second == "M")
a[i] = make_pair(2, 0);
else if (second == "L")
a[i] = make_pair(3, 0);
else if (second == "XL")
a[i] = make_pair(4, 0);
else if (second == "XXL")
a[i] = make_pair(5, 0);
else if (second == "XXXL")
a[i] = make_pair(6, 0);
else if (second[0] == 'S')
a[i] = make_pair(1, 1);
else if (second[0] == 'M')
a[i] = make_pair(2, 1);
else if (second[0] == 'L')
a[i] = make_pair(3, 1);
else if (second[1] == 'L')
a[i] = make_pair(4, 1);
else if (second[2] == 'L')
a[i] = make_pair(5, 1);
else
a[i] = make_pair(6, 1);
}
for (int i = 1; i <= n; i++)
if (a[i].second == 0) {
if (b[a[i].first] != 0) {
ans[i] = da[a[i].first];
b[a[i].first]--;
}
}
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= n; j++)
if (ans[j] == "" && a[j].second == 1) {
if (a[j].first + 1 == i && b[i] > 0) {
b[i]--;
ans[j] = da[i];
}
}
for (int j = 1; j <= n; j++)
if (ans[j] == "" && a[j].second == 1) {
if (a[j].first == i && b[i] > 0) {
b[i]--;
ans[j] = da[i];
}
}
}
for (int i = 1; i <= n; i++)
if (ans[i] == "") {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
for (int i = 1; i <= n; i++) cout << ans[i] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
char ans[100005][7];
char shirts[6][7] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int GetId(char *s) {
if (s[0] == 'S') return 0;
if (s[0] == 'M') return 1;
if (s[0] == 'L') return 2;
if (s[1] == 'L') return 3;
if (s[2] == 'L') return 4;
if (s[3] == 'L') return 5;
}
void Present(int idp, int idc) {
int l = strlen(shirts[idc]);
for (int i = 0; i <= l; ++i) ans[idp][i] = shirts[idc][i];
}
int main() {
int a[10];
vector<int> g[10];
for (int i = 0; i < 6; ++i) g[i].clear();
for (int i = 0; i < 6; ++i) scanf("%d", &a[i]);
int n;
bool ok = true;
scanf("%d", &n);
for (int k = 0; k < n; ++k) {
char s[1005];
scanf("%s", s);
int l = strlen(s), i = 0;
while (i < l && (s[i] != ',')) ++i;
if (i != l) {
s[i] = '\0';
g[GetId(s)].push_back(k);
} else {
int id = GetId(s);
if (a[id] > 0) {
a[id]--;
Present(k, id);
} else
ok = false;
}
}
for (int i = 0; i < 5; ++i) {
int m = g[i].size();
if (m <= a[i]) {
for (int j = 0; j < m; ++j) Present(g[i][j], i);
} else {
for (int j = 0; j < a[i]; ++j) Present(g[i][j], i);
if ((m - a[i]) > a[i + 1]) {
ok = false;
break;
} else {
for (int j = a[i]; j < m; ++j) Present(g[i][j], i + 1);
a[i + 1] -= (m - a[i]);
}
}
}
if (g[5].size() <= a[5]) {
for (int i = 0; i < g[5].size(); ++i) Present(g[5][i], 5);
} else
ok = false;
if (ok) {
printf("YES\n");
for (int i = 0; i < n; ++i) printf("%s\n", ans[i]);
} else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1e18 + 5;
const int N = 2e5 + 105, M = 1e6 + 5;
int n;
int cnt, head[N], a[6];
map<string, int> id;
map<int, string> rid;
struct node {
int next, to, w;
} e[M << 1];
inline void add(int u, int v, int w) {
e[++cnt].next = head[u];
e[cnt].to = v;
e[cnt].w = w;
head[u] = cnt;
}
struct Dinic {
int n, m, s, t;
int dep[N], cur[N];
void init(int n, int s, int t) {
this->s = s, this->t = t, this->n = n;
cnt = 1, m = 0;
memset(head, 0, (n + 1) * sizeof(int));
}
void addedge(int u, int v, int cap) {
add(u, v, cap);
add(v, u, 0);
m += 2;
}
bool bfs() {
memset(dep, 0, (n + 1) * sizeof(int));
memcpy(cur, head, (n + 1) * sizeof(int));
queue<int> q;
q.push(s);
dep[s] = 1;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int i = head[u]; i; i = e[i].next) {
int v = e[i].to;
if (!dep[v] && e[i].w > 0) {
dep[v] = dep[u] + 1;
q.push(v);
}
}
}
return dep[t];
}
int dfs(int u, int flow) {
if (u == t || !flow) return flow;
int used = flow;
for (int i = cur[u]; i; i = e[i].next) {
cur[u] = i;
int v = e[i].to;
if (dep[v] == dep[u] + 1) {
int low = dfs(v, min(flow, e[i].w));
e[i].w -= low;
e[i ^ 1].w += low;
flow -= low;
if (!flow) break;
}
}
return used - flow;
}
int go() {
int maxflow = 0;
while (bfs()) maxflow += dfs(s, INF);
return maxflow;
}
} MF;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
id["S"] = 0;
id["M"] = 1;
id["L"] = 2;
id["XL"] = 3;
id["XXL"] = 4;
id["XXXL"] = 5;
rid[0] = "S";
rid[1] = "M";
rid[2] = "L";
rid[3] = "XL";
rid[4] = "XXL";
rid[5] = "XXXL";
for (int i = 0; i <= 5; i++) cin >> a[i];
cin >> n;
MF.init(2 * n + 8, 0, 2 * n + 7);
for (int i = 0; i <= 5; i++) MF.addedge(2 * n + i + 1, MF.t, a[i]);
for (int i = 1; i <= n; i++) {
string s, x, y;
cin >> s;
bool tag = 0;
MF.addedge(2 * i - 1, 2 * i, 1);
MF.addedge(MF.s, 2 * i - 1, INF);
for (int j = 0; j < (int)s.size(); j++) {
if (s[j] == ',') {
tag = 1;
x = s.substr(0, j);
y = s.substr(j + 1);
MF.addedge(2 * i, 2 * n + id[x] + 1, 1);
MF.addedge(2 * i, 2 * n + id[y] + 1, 1);
break;
}
}
if (!tag) MF.addedge(2 * i, 2 * n + id[s] + 1, 1);
}
int res = MF.go();
if (res != n) return cout << "NO", 0;
cout << "YES" << '\n';
for (int u = 1; u <= n; u++) {
for (int i = head[2 * u]; i; i = e[i].next) {
int v = e[i].to, w = e[i].w;
if (v - 2 * n - 1 < 0) continue;
if (!w) cout << rid[v - 2 * n - 1] << '\n';
}
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("fast-math")
using namespace std;
const int INF = 1e9;
const long long INFll = 2e18;
const int BASE1 = 179;
const int BASE2 = 653;
const long long MOD = 1e9 + 7;
const int MAXN = 2e5;
const long double PI = 3.1415926535;
const long double EPS = 1e-15;
vector<string> m1 = {"S", "S,M", "M", "M,L", "L", "L,XL",
"XL", "XL,XXL", "XXL", "XXL,XXXL", "XXXL"};
bool cmp(pair<string, int> a, pair<string, int> b) {
return (find(m1.begin(), m1.end(), a.first) - m1.begin()) <
(find(m1.begin(), m1.end(), b.first) - m1.begin());
}
void solve() {
vector<int> cnt(6);
for (int i = 0; i < (6); i++) cin >> cnt[i];
map<string, int> m = {{"S", 0}, {"M", 1}, {"L", 2},
{"XL", 3}, {"XXL", 4}, {"XXXL", 5}};
vector<string> dop;
int n;
cin >> n;
vector<pair<string, int>> a(n);
for (int i = 0; i < (n); i++) {
string s;
cin >> s;
a[i] = make_pair(s, i);
}
sort(a.begin(), a.end(), cmp);
vector<string> res(n, "###");
for (int i = 0; i < (n); i++) {
string s = a[i].first;
if (s.find(',')) {
string s1 = s.substr(0, s.find(','));
string s2 =
s.substr(s.find(',') + 1, ((int)(s).size()) - ((int)(s1).size()) - 1);
if (cnt[m[s1]] > 0) {
cnt[m[s1]]--;
res[a[i].second] = s1;
} else if (cnt[m[s2]] > 0) {
cnt[m[s2]]--;
res[a[i].second] = s2;
}
} else {
if (cnt[m[s]] > 0) {
cnt[m[s]]--;
res[a[i].second] = s;
}
}
}
bool flag = true;
for (int i = 0; i < (n); i++) {
if (res[i] == "###") flag = false;
}
if (flag) {
cout << "YES\n";
for (int i = 0; i < (n); i++) cout << res[i] << "\n";
} else
cout << "NO\n";
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << setprecision(14) << fixed;
int t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXV = 1e5 + 15;
int n;
struct edge {
int from, to, f;
};
const int MAX = 1e5 + 15;
int s, t, pt[MAX], d[MAX];
vector<edge> e;
vector<int> g[MAX];
queue<int> q;
typedef int type;
void init(int s_, int t_) {
s = s_, t = t_;
for (int i = s; i <= t; i++) g[i].clear();
e.clear();
}
void addEdge(int from, int to, type c, type cr = 0) {
edge ed;
ed.from = from, ed.to = to, ed.f = c;
e.push_back(ed);
g[from].push_back((int)e.size() - 1);
ed.from = to, ed.to = from, ed.f = cr;
e.push_back(ed);
g[to].push_back((int)e.size() - 1);
}
bool bfs() {
for (int i = s; i <= t; i++) d[i] = -1;
d[s] = 0;
q.push(s);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int i = 0; i < (int)g[u].size(); i++) {
int id = g[u][i];
int v = e[id].to;
if (d[v] == -1 && e[id].f > 0) {
d[v] = d[u] + 1;
q.push(v);
}
}
}
return d[t] != -1;
}
type dfs(int u, type flow = 1e9) {
if (u == t) return flow;
for (; pt[u] < (int)g[u].size(); pt[u]++) {
int id = g[u][pt[u]];
int v = e[id].to;
if (d[u] + 1 != d[v] || e[id].f == 0) continue;
type pushed = dfs(v, min(flow, e[id].f));
if (pushed > 0) {
e[id].f -= pushed;
e[id ^ 1].f += pushed;
return pushed;
}
}
return 0;
}
type getMaxFlow() {
type ans = 0;
while (1) {
if (!bfs()) break;
for (int i = s; i <= t; i++) pt[i] = 0;
type f;
while ((f = dfs(s))) ans += f;
}
return ans;
}
long long tot[101];
int get_id(const string& size) {
if (size == "S") return 1;
if (size == "M") return 2;
if (size == "L") return 3;
if (size == "XL") return 4;
if (size == "XXL") return 5;
return 6;
}
int main() {
s = 0;
for (int i = 1; i <= 6; i++) {
scanf("%I64d", &tot[i]);
}
scanf("%d\n", &n);
t = n + 7;
init(0, t);
for (int i = 1; i <= 6; i++) {
addEdge(i, t, tot[i]);
}
for (int i = 1; i <= n; i++) {
char cad[107];
scanf("%s", cad);
int len = strlen(cad);
int comma = -1;
for (int i = 0; i < len; i++)
if (cad[i] == ',') comma = i;
if (comma == -1)
addEdge(i + 6, get_id(string(cad)), 1);
else {
string sz0 = "", sz1 = "";
for (int i = 0; i < comma; i++) sz0 += cad[i];
for (int i = comma + 1; i < len; i++) sz1 += cad[i];
addEdge(i + 6, get_id(sz0), 1);
addEdge(i + 6, get_id(sz1), 1);
}
addEdge(s, i + 6, 1);
}
int max_match = getMaxFlow();
if (max_match != n)
printf("NO\n");
else {
printf("YES\n");
for (int x = 7; x <= n + 6; x++)
for (int ed : g[x]) {
if (e[ed].f == 0 && e[ed].to != s) {
if (e[ed].to == 1)
printf("S");
else if (e[ed].to == 2)
printf("M");
else if (e[ed].to == 3)
printf("L");
else if (e[ed].to == 4)
printf("XL");
else if (e[ed].to == 5)
printf("XXL");
else if (e[ed].to == 6)
printf("XXXL");
printf("\n");
break;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct pi {
int first, first2, mid, second, second2;
};
const int N = 1e5 + 20;
int D;
int a[6], n, ans[N];
vector<pair<int, int> > b;
string _s[] = {"S", "M", "L", "XL", "XXL", "XXXL"};
bool dasht(string s) {
for (int i = 0; i < s.size(); ++i)
if (s[i] == ',') return true;
return false;
}
int adad(int l, int r, string s) {
string s1;
for (int i = l; i < r; ++i) s1 += s[i];
int x;
for (int i = 0; i < 6; ++i)
if (_s[i] == s1) {
x = i;
break;
}
return x;
}
int find(string s) {
int x;
for (int i = 0; i < s.size(); ++i)
if (s[i] == ',') {
x = i;
break;
}
return x;
}
int main() {
for (int i = 0; i < 6; ++i) cin >> a[i];
cin >> n;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
if (!dasht(s)) {
int x = adad(0, int(s.size()), s);
if (a[x] == 0) {
cout << "NO\n";
return 0;
}
a[x]--;
ans[i] = x;
} else {
int x = find(s);
int y = adad(0, x, s);
b.push_back(make_pair(y, i));
}
}
sort(b.begin(), b.end());
for (int i = 0; i < b.size(); ++i) {
if (a[b[i].first] > 0) {
a[b[i].first]--;
ans[b[i].second] = b[i].first;
} else if (a[b[i].first + 1] != 0) {
a[b[i].first + 1]--;
ans[b[i].second] = b[i].first + 1;
} else {
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
for (int i = 0; i < n; i++) cout << _s[ans[i]] << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
const double PI = acos(-1.0);
long long gcd(long long a, long long b) {
long long m;
while (b) {
m = a % b;
a = b;
b = m;
}
return a;
}
int rome_number(char s[]) {
if (s[0] == 'S') return 0;
if (s[0] == 'M') return 1;
if (s[0] == 'L') return 2;
if (s[0] == 'X') {
if (s[1] == 'L') return 3;
if (s[1] == 'X') {
if (s[2] == 'L')
return 4;
else
return 5;
}
}
}
int solve() {
long long sz[6];
long long g[6] = {}, g2[6] = {};
vector<pair<int, int> > v;
int n;
for (int i = 0; i < 6; ++i) cin >> sz[i];
cin >> n;
v.resize(n);
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
s += ',';
char t[16];
int j = 0;
int a = -1, b = -1, c = 0;
for (int k = 0; k < s.size(); ++k) {
t[j++] = s[k];
if (s[k] == ',') {
if (c == 0)
a = rome_number(t);
else
b = rome_number(t);
++c;
j = 0;
}
}
v[i] = make_pair(a, b);
}
vector<int> ans(n, -1);
for (int h = 0; h < 6; ++h) {
int S_0 = 0, S_1 = 0;
for (int i = 0; i < n; ++i) {
if (v[i].first == h) {
if (v[i].second == h + 1)
S_1++;
else
S_0++;
}
}
if (S_0 > sz[h]) {
puts("NO");
return 0;
}
if (S_0 + S_1 > sz[h]) S_1 = sz[h] - S_0;
for (int i = 0; i < n; ++i) {
if (v[i].first == h) {
if (v[i].second == h + 1) {
if (S_1 > 0) {
ans[i] = h;
v[i].first = -1;
v[i].second = -1;
--S_1;
} else {
v[i].first = h + 1;
v[i].second = -1;
}
} else {
v[i].first = -1;
ans[i] = h;
S_0--;
}
}
}
}
printf("YES\n");
for (int i = 0; i < n; ++i) {
typedef char const* pchar;
const pchar ROME[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
printf("%s\n", ROME[ans[i]]);
}
return 0;
}
int main() { solve(); }
|
#include <bits/stdc++.h>
using namespace std;
int a[7] = {0}, n, i, an[100010], num[100010] = {0}, j, re[100010] = {0}, cnt;
char x[10], no[10][10] = {"S", "M", "L", "XL", "XXL", "XXXL"}, *lo;
int main() {
for (i = 0; i < 6; i++) {
scanf("%d", &a[i]);
}
memset(re, -1, sizeof(re));
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", x);
lo = strchr(x, ',');
if (lo != NULL) {
*lo = '\0';
for (j = 0; j < 6; j++) {
if (strcmp(x, no[j]) == 0) {
num[j]++;
re[i] = j;
break;
}
}
} else {
for (j = 0; j < 6; j++) {
if (strcmp(x, no[j]) == 0) {
an[i] = j;
a[j]--;
break;
}
}
}
memset(x, 0, sizeof(x));
}
for (i = 0; i < 6; i++) {
if (a[i] < 0) {
printf("NO");
return 0;
}
}
for (i = 0; i < 6; i++) {
if (a[i] >= num[i]) {
for (j = 0; j < n; j++) {
if (re[j] == i) {
an[j] = i;
}
}
a[i] -= num[i];
num[i] = 0;
} else {
cnt = a[i];
for (j = 0; j < n; j++) {
if (re[j] == i) {
if (cnt > 0) {
an[j] = i;
cnt--;
} else {
an[j] = i + 1;
}
}
}
num[i] -= a[i];
a[i] = 0;
a[i + 1] -= num[i];
}
if (a[i] < 0 || a[i + 1] < 0) {
printf("NO");
return 0;
}
}
printf("YES\n");
for (i = 0; i < n; i++) {
if (an[i] == 0)
printf("S\n");
else if (an[i] == 1)
printf("M\n");
else if (an[i] == 2)
printf("L\n");
else if (an[i] == 3)
printf("XL\n");
else if (an[i] == 4)
printf("XXL\n");
else if (an[i] == 5)
printf("XXXL\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
char s[20];
char size[20][20] = {"S", "M", "L", "XL", "XXL", "XXXL",
"S,M", "M,L", "L,XL", "XL,XXL", "XXL,XXXL"};
int num[10];
vector<int> cnt1[10], cnt2[10];
int n;
int p[maxn];
int main() {
for (int i = 0; i < 6; i++) {
scanf("%d", num + i);
}
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s);
for (int j = 0; j < 11; j++) {
if (strcmp(s, size[j]) == 0) {
if (j < 6) {
cnt1[j].push_back(i);
} else {
cnt2[j - 6].push_back(i);
}
p[i] = j;
break;
}
}
}
for (int i = 0; i < 6; i++) {
num[i] -= cnt1[i].size();
if (num[i] < 0) {
printf("NO\n");
return 0;
}
}
int pos = 0;
for (int i = 0; num[0] > 0 && i < cnt2[0].size(); i++) {
p[cnt2[0][pos++]] = 0;
num[0]--;
}
for (int i = 0; i < 5; i++) {
for (int j = pos; j < cnt2[i].size(); j++) {
p[cnt2[i][j]] = i + 1;
num[i + 1]--;
}
if (num[i + 1] < 0) {
printf("NO\n");
return 0;
}
pos = 0;
for (int j = 0; num[i + 1] > 0 && j < cnt2[i + 1].size(); j++) {
num[i + 1]--;
p[cnt2[i + 1][pos++]] = i + 1;
}
}
if (num[5] < 0) {
printf("NO\n");
} else {
printf("YES\n");
for (int i = 0; i < n; i++) {
printf("%s\n", size[p[i]]);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int get(string s) {
if (s == "S") return 1;
if (s == "M") return 2;
if (s == "L") return 3;
if (s == "XL") return 4;
if (s == "XXL") return 5;
if (s == "XXXL") return 6;
}
void rev(int x) {
if (x == 1) puts("S");
if (x == 2) puts("M");
if (x == 3) puts("L");
if (x == 4) puts("XL");
if (x == 5) puts("XXL");
if (x == 6) puts("XXXL");
}
struct Dinic {
int V, E, src, tar;
int head[400100], work[400100], dis[400100];
int to[4000200], cap[4000200], nxt[4000200];
int q[400100], qf, qb;
void init(int n, int s, int t) {
V = n + 2;
E = 0;
src = s;
tar = t;
memset(head, -1, sizeof(int) * V);
}
void add_edge(int u, int v, int c) {
to[E] = v;
cap[E] = c;
nxt[E] = head[u];
head[u] = E++;
to[E] = u;
cap[E] = 0;
nxt[E] = head[v];
head[v] = E++;
}
bool bfs() {
memset(dis, -1, sizeof(int) * V);
qf = qb = 0;
q[qb++] = src;
dis[src] = 0;
while (qf < qb && dis[tar] == -1) {
int u = q[qf++];
for (int i = head[u]; i >= 0; i = nxt[i]) {
int v = to[i];
if (dis[v] == -1 && cap[i] > 0) {
dis[v] = dis[u] + 1;
q[qb++] = v;
}
}
}
return dis[tar] >= 0;
}
int dfs(int u, int &bot) {
int v, bot1, delta;
if (u == tar) return bot;
for (int &i = work[u]; i >= 0; i = nxt[i]) {
int v = to[i];
if (dis[v] != dis[u] + 1 || cap[i] == 0) continue;
bot1 = min(bot, cap[i]);
if (delta = dfs(v, bot1)) {
cap[i] -= delta;
cap[i ^ 1] += delta;
bot = bot1;
return delta;
}
}
return 0;
}
int dinic() {
int ans = 0, delta, bot;
while (bfs()) {
memcpy(work, head, sizeof(int) * V);
delta = 0x3f3f3f3f;
while (delta = dfs(src, bot = 0x3f3f3f3f)) ans += delta;
}
return ans;
}
} dinic;
int num[400100];
char s[400100];
string st;
int main() {
for (int i = 1; i <= 6; i++) scanf("%d", num + i);
int n;
scanf("%d", &n);
dinic.init(n + 8, n + 7, n + 8);
for (int i = 1; i <= n; i++) {
scanf("%s", s);
int len = strlen(s), flag = 1;
for (int j = 0; j < len; j++)
if (s[j] == ',') {
flag = 0;
st.clear();
for (int k = 0; k < j; k++) st.push_back(s[k]);
int u = get(st);
dinic.add_edge(i, n + u, 1);
st.clear();
for (int k = j + 1; k < len; k++) st.push_back(s[k]);
u = get(st);
dinic.add_edge(i, n + u, 1);
}
if (flag) {
st.clear();
for (int j = 0; j < len; j++) st.push_back(s[j]);
int u = get(st);
dinic.add_edge(i, n + u, 1);
}
}
for (int i = 1; i <= n; i++) dinic.add_edge(n + 7, i, 1);
for (int i = 1; i <= 6; i++) dinic.add_edge(n + i, n + 8, num[i]);
if (dinic.dinic() == n) {
puts("YES");
for (int u = 1; u <= n; u++) {
for (int e = dinic.head[u]; ~e; e = dinic.nxt[e]) {
int v = dinic.to[e];
if (n + 1 <= v && v <= n + 6 && dinic.cap[e ^ 1]) {
rev(v - n);
break;
}
}
}
} else
puts("NO");
}
|
#include <bits/stdc++.h>
const double eps = 1e-10;
const float epsf = 1e-6;
using namespace std;
inline long long int __gcd(long long int a, long long int b) {
if (a == 0 || b == 0) {
return max(a, b);
}
long long int tempa, tempb;
while (1) {
if (a % b == 0)
return b;
else {
tempa = a;
tempb = b;
a = tempb;
b = tempa % tempb;
}
}
}
inline int compfloat(float& x, float& y) {
if (fabs(x - y) < epsf)
return 0;
else if (x - y > 0)
return 1;
return -1;
}
inline int compdouble(double x, double y) {
if (fabs(x - y) < eps)
return 0;
else if (x - y > 0)
return 1;
else
return -1;
}
bool prime(long long int k) {
for (long long int i = 2; i * i <= k; i++)
if (k % i == 0) {
return false;
}
return true;
}
void pdash(int n = 1) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < 30; j++) {
cout << "-";
}
cout << "\n";
}
}
long long int power(long long int x, long long int y) {
long long int result = 1;
while (y > 0) {
if (y & 1) {
result = (result * x);
}
y = y >> 1;
x = (x * x);
}
return result;
}
long long int power(long long int x, long long int y, long long int z) {
long long int result = 1;
x = x % z;
while (y > 0) {
if (y & 1) {
result = (result * x) % z;
}
y = y >> 1;
x = (x * x) % z;
}
return result;
}
long long int modInverse(long long int n, long long int p) {
return power(n, p - 2, p);
}
long long int nCrF(long long int n, long long int r, long long int p) {
if (r == 0) return 1;
long long int f[n + 1];
f[0] = 1;
for (long long int i = 1; i <= n; i++) f[i] = f[i - 1] * i % p;
return (f[n] * modInverse(f[r], p) % p * modInverse(f[n - r], p) % p) % p;
}
void cordinate_compression(vector<int>& v) {
vector<int> p = v;
sort(p.begin(), p.end());
p.erase(unique(p.begin(), p.end()), p.end());
for (int i = 0; i < (int)((v).size()); i++)
v[i] = (int)(lower_bound(p.begin(), p.end(), v[i]) - p.begin());
}
void solve() {
map<int, string> rmp;
map<string, int> mp;
mp["S"] = 0;
mp["M"] = 1;
mp["L"] = 2;
mp["XL"] = 3;
mp["XXL"] = 4;
mp["XXXL"] = 5;
rmp[0] = "S";
rmp[1] = "M";
rmp[2] = "L";
rmp[3] = "XL";
rmp[4] = "XXL";
rmp[5] = "XXXL";
vector<int> vec(6);
for (auto& j : vec) {
cin >> j;
}
vector<pair<int, int> > people[6];
int n;
cin >> n;
vector<int> booking(n, -1);
vector<bool> is_booked(n, false);
string str;
for (int i = 0; i < n; i++) {
cin >> str;
int pz = 0;
for (int i = 0; i < (int)((str).size()); i++) {
if (str[i] == ',') {
pz = i;
}
}
if (pz) {
int i1 = mp[string(str.begin(), str.begin() + pz)],
i2 = mp[string(str.begin() + (pz + 1), str.end())];
if (i1 > i2) swap(i1, i2);
people[i1].push_back({i1, i});
people[i2].push_back({i1, i});
} else {
vec[mp[str]]--;
booking[i] = mp[str];
is_booked[i] = 1;
if (vec[mp[str]] < 0) {
cout << "NO\n";
return;
}
}
}
for (int i = 0; i < 6; i++) {
sort(people[i].begin(), people[i].end());
reverse(people[i].begin(), people[i].end());
}
for (int i = 0; i < 6; i++) {
while ((int)((people[i]).size()) and vec[i] > 0) {
int p = people[i].back().second;
people[i].pop_back();
if (is_booked[p]) continue;
vec[i]--;
booking[p] = i;
is_booked[p] = 1;
}
}
for (int i = 0; i < n; i++) {
if (booking[i] == -1) {
cout << "NO\n";
return;
}
}
cout << "YES\n";
for (int i = 0; i < n; i++) {
cout << rmp[booking[i]] << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> A[6];
int rec[100010], num[6], n, i, j, opt, l;
char s[10];
inline int check(int l, int r) {
if (l == r) {
if (s[l] == 'S') return 0;
if (s[l] == 'M') return 1;
if (s[l] == 'L') return 2;
}
if (r - l + 1 == 2) return 3;
if (r - l + 1 == 3) return 4;
if (r - l + 1 == 4) return 5;
}
inline void out(int i) {
switch (i) {
case 0:
puts("S");
break;
case 1:
puts("M");
break;
case 2:
puts("L");
break;
case 3:
puts("XL");
break;
case 4:
puts("XXL");
break;
case 5:
puts("XXXL");
break;
}
}
int main() {
for (i = 0; i < 6; i++) scanf("%d", &num[i]);
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", s);
l = strlen(s);
for (j = 0; j < l; j++)
if (s[j] == ',') break;
if (j == l) {
opt = check(0, l - 1);
if (num[opt] == 0) {
puts("NO");
return 0;
} else
num[opt]--;
rec[i] = opt;
} else {
opt = check(0, j - 1);
A[opt].push_back(i);
}
}
for (i = 0; i < 6; i++)
for (j = 0; j < A[i].size(); j++)
if (num[i] > 0)
rec[A[i][j]] = i, num[i]--;
else {
if (num[i + 1] == 0 || i == 5) {
puts("NO");
return 0;
}
rec[A[i][j]] = i + 1, num[i + 1]--;
}
puts("YES");
for (i = 0; i < n; i++) out(rec[i]);
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[7], c[7], n;
map<string, int> s;
string temp, x, y, ans[maxn];
struct p {
string ans, x, y;
int flag, pos;
} b[maxn];
int cmp1(p a, p b) {
if (a.flag == b.flag) {
return s[a.x] < s[b.x];
}
return a.flag > b.flag;
}
int cmp2(p a, p b) { return a.pos < b.pos; }
void read() {
for (int i = 1; i <= 6; i++) scanf("%d", &a[i]);
scanf("%d", &n);
for (int j = 1; j <= n; j++) {
cin >> temp;
int pos = -1, flag = 0;
for (int i = 0; i < temp.size(); i++) {
if (temp[i] == ',') {
pos = i;
flag = 1;
break;
}
}
b[j].pos = j;
if (!flag)
a[s[temp]]--, b[j].ans = temp;
else {
x = temp.substr(0, pos);
y = temp.substr(pos + 1);
b[j].x = x, b[j].y = y;
b[j].flag = 2;
}
}
}
int main() {
s["S"] = 1, s["M"] = 2, s["L"] = 3, s["XL"] = 4, s["XXL"] = 5, s["XXXL"] = 6;
read();
sort(b + 1, b + 1 + n, cmp1);
for (int i = 1; i <= 6; i++) {
if (a[i] < 0) {
cout << "NO" << endl;
return 0;
}
}
for (int i = 1; i <= n; i++) {
if (b[i].flag != 2) continue;
if (a[s[b[i].x]] - 1 >= 0) {
b[i].ans = b[i].x;
a[s[b[i].x]]--;
} else {
if (a[s[b[i].y]] - 1 >= 0) {
b[i].ans = b[i].y;
a[s[b[i].y]]--;
} else {
cout << "NO";
return 0;
}
}
}
sort(b + 1, b + 1 + n, cmp2);
cout << "YES" << endl;
for (int i = 1; i <= n; i++) cout << b[i].ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
int sizetoint(string &s) {
if (s == "S") return 0;
if (s == "M") return 1;
if (s == "L") return 2;
if (s == "XL") return 3;
if (s == "XXL") return 4;
if (s == "XXXL") return 5;
}
string numtosize(int x) {
if (x == 0) return "S";
if (x == 1) return "M";
if (x == 2) return "L";
if (x == 3) return "XL";
if (x == 4) return "XXL";
if (x == 5) return "XXXL";
}
pair<int, int> stopair(string &s) {
string first = "", second = "";
bool flag = false;
for (int i = 0; i < s.size(); ++i) {
if (!flag && s[i] != ',')
first = first + s[i];
else if (!flag && s[i] == ',')
flag = true;
else if (flag)
second = second + s[i];
}
pair<int, int> ans;
ans.first = sizetoint(first);
if (flag)
ans.second = sizetoint(second);
else
ans.second = -1;
return ans;
}
int main() {
vector<int> cnt(6);
for (int i = 0; i < 6; ++i) cin >> cnt[i];
int n;
string s;
cin >> n;
vector<vector<int> > first(6), second(6);
vector<string> ans(n, "");
pair<int, int> x;
for (int i = 0; i < n; ++i) {
cin >> s;
x = stopair(s);
if (x.second == -1) {
--cnt[x.first];
if (cnt[x.first] < 0) {
cout << "NO\n";
return 0;
}
ans[i] = numtosize(x.first);
} else {
first[x.first].push_back(i);
second[x.second].push_back(i);
}
}
int j;
for (int i = 0; i < 6; ++i) {
j = 0;
while (j < second[i].size() && cnt[i] > 0) {
if (ans[second[i][j]] == "") {
--cnt[i];
ans[second[i][j]] = numtosize(i);
}
++j;
}
j = 0;
while (j < first[i].size() && cnt[i] > 0) {
if (ans[first[i][j]] == "") {
--cnt[i];
ans[first[i][j]] = numtosize(i);
}
++j;
}
}
for (int i = 0; i < n; ++i) {
if (ans[i] == "") {
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
for (int i = 0; i < n; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
static const char *L[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
static int A[6];
static pair<int, int> W[100000];
static vector<int> V[6][6];
static void bye() {
puts("NO");
exit(0);
}
static int find(const char *p) {
for (auto i = 0; i < 6; i++)
if (strcmp(L[i], p) == 0) return i;
throw;
}
static pair<int, int> read() {
char buf[16];
scanf("%s", buf);
auto p = strchr(buf, ',');
if (p == nullptr) {
auto x = find(buf);
return pair<int, int>(x, x);
}
*p = '\0';
return pair<int, int>(find(buf), find(p + 1));
}
int main() {
for (auto i = 0; i < 6; i++) scanf("%d", A + i);
int N;
scanf("%d", &N);
for (auto i = 0; i < N; i++) {
W[i] = read();
if (W[i].first == W[i].second) {
if (--A[W[i].first] < 0) bye();
} else {
V[W[i].first][W[i].second].push_back(i);
}
}
for (auto i = 1; i < 6; i++) {
for (auto &j : V[i - 1][i]) {
if (A[i - 1] != 0) {
A[i - 1]--;
} else if (A[i] != 0) {
A[i]--;
W[j].first = i;
} else {
bye();
}
}
}
puts("YES");
for (auto i = 0; i < N; i++) puts(L[W[i].first]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct node {
int a, b;
int id;
};
vector<node> tp;
int vis[111111];
bool cmp(node x, node y) {
if (x.a != y.a) return x.a < y.a;
return x.b < y.b;
}
int check(char s[]) {
if (strcmp(s, "S") == 0) return 0;
if (strcmp(s, "M") == 0) return 1;
if (strcmp(s, "L") == 0) return 2;
if (strcmp(s, "XL") == 0) return 3;
if (strcmp(s, "XXL") == 0) return 4;
if (strcmp(s, "XXXL") == 0) return 5;
}
char str[10][10] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int main() {
int s[10];
int n, m, i, j;
int flag = 0;
for (i = 0; i < 6; i++) cin >> s[i];
cin >> n;
char g[30];
for (i = 1; i <= n; i++) {
cin >> g;
m = strlen(g);
for (j = 0; j < m; j++) {
if (g[j] == ',') {
g[j] = '\0';
break;
}
}
if (j == m) {
s[check(g)]--;
if (s[check(g)] < 0) flag = 1;
vis[i] = check(g);
} else {
node tmp;
tmp.a = check(g);
tmp.b = check(g + j + 1);
tmp.id = i;
if (tmp.a > tmp.b) {
swap(tmp.a, tmp.b);
}
tp.push_back(tmp);
}
}
sort(tp.begin(), tp.end(), cmp);
for (i = 0; i < tp.size(); i++) {
if (s[tp[i].a] > 0) {
s[tp[i].a]--;
vis[tp[i].id] = tp[i].a;
} else {
s[tp[i].b]--;
vis[tp[i].id] = tp[i].b;
}
if (s[tp[i].a] < 0 || s[tp[i].b] < 0) flag = 1;
}
if (flag)
printf("NO\n");
else {
printf("YES\n");
for (i = 1; i <= n; i++) {
printf("%s\n", str[vis[i]]);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int out[100005];
vector<int> want[6];
char s[6][10] = {"S", "M", "L", "XL", "XXL", "XXXL"};
char t[5][10] = {"S,M", "M,L", "L,XL", "XL,XXL", "XXL,XXXL"};
char u[10];
int a[6];
int main() {
scanf("%d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]);
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", u);
for (int j = 0; j < 6; j++) {
if (strcmp(u, s[j]) == 0) {
out[i] = j;
a[j]--;
if (a[j] == -1) {
printf("NO\n");
return 0;
}
break;
}
}
for (int j = 0; j < 5; j++) {
if (strcmp(u, t[j]) == 0) {
want[j].push_back(i);
break;
}
}
}
for (int i = 0; i < 5; i++) {
for (auto x : want[i]) {
if (a[i]) {
out[x] = i;
a[i]--;
} else if (a[i + 1]) {
out[x] = i + 1;
a[i + 1]--;
} else {
printf("NO\n");
return 0;
}
}
}
printf("YES\n");
for (int i = 1; i <= n; i++) {
printf("%s\n", s[out[i]]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> mapi;
map<int, string> inv;
vector<vector<int> > vec(100);
int a[12], haha[12];
int ans[123456];
int main() {
std::ios::sync_with_stdio(false);
int i;
for (i = 0; i < 6; i++) {
cin >> a[i];
}
mapi["S"] = 0;
mapi["M"] = 1;
mapi["L"] = 2;
mapi["XL"] = 3;
mapi["XXL"] = 4;
mapi["XXXL"] = 5;
int n;
cin >> n;
map<string, int>::iterator it;
for (it = mapi.begin(); it != mapi.end(); it++) {
inv[it->second] = it->first;
}
string s, str;
int val, j, flag, val1;
for (j = 0; j < n; j++) {
cin >> s;
val = s.find(',');
str = "";
for (i = val + 1; i < s.length(); i++) {
str += s[i];
}
val1 = mapi[str];
flag = 0;
str = "";
for (i = 0; i < val; i++) {
flag = 1;
str += s[i];
}
if (flag) {
val1 = min(val1, mapi[str]);
haha[val1]++;
vec[val1].push_back(j);
} else {
if (!a[val1]) {
cout << "NO" << endl;
return 0;
}
a[val1]--;
ans[j] = val1;
}
}
for (i = 0; i < 5; i++) {
j = 0;
while (haha[i] > 0) {
if (a[i] > 0) {
ans[vec[i][j]] = i;
a[i]--;
} else if (a[i + 1]) {
ans[vec[i][j]] = i + 1;
a[i + 1]--;
} else {
cout << "NO" << endl;
return 0;
}
haha[i]--;
j++;
}
}
cout << "YES" << endl;
for (i = 0; i < n; i++) {
cout << inv[ans[i]] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
const long long INF = (1LL << 61);
const int inf = 2e9;
using namespace std;
void solve();
int main() { solve(); }
const int N = 300005;
map<string, int> num;
int cnt[6], n, ans[N];
string buf[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
bool u[N];
vector<int> only_one[6];
vector<int> can_next[6];
string s, ss;
void solve() {
num["S"] = 0;
num["M"] = 1;
num["L"] = 2;
num["XL"] = 3;
num["XXL"] = 4;
num["XXXL"] = 5;
for (int i = 0; i < 6; i++) cin >> cnt[i];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
ss = "";
int j;
for (j = 0; j < (int)s.size() && s[j] != ','; j++) ss += s[j];
if (j == (int)s.size())
only_one[num[ss]].push_back(i);
else {
can_next[num[ss]].push_back(i);
only_one[num[ss] + 1].push_back(i);
}
}
for (int i = 0; i < 6; i++) {
for (int j = 0; j < (int)only_one[i].size() && cnt[i] != 0; j++) {
if (u[only_one[i][j]]) continue;
u[only_one[i][j]] = 1;
cnt[i]--;
ans[only_one[i][j]] = i;
}
for (int j = 0; j < (int)can_next[i].size() && cnt[i] != 0; j++) {
if (u[can_next[i][j]]) continue;
u[can_next[i][j]] = 1;
cnt[i]--;
ans[can_next[i][j]] = i;
}
}
for (int i = 1; i <= n; i++) {
if (u[i] == 0) {
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
for (int i = 1; i <= n; i++) cout << buf[ans[i]] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
struct flow_graph {
int MAX_V, E, s, t, head, tail;
int *cap, *to, *next, *last, *dist, *q, *now;
flow_graph() {}
flow_graph(int V, int MAX_E) {
MAX_V = V;
E = 0;
cap = new int[2 * MAX_E], to = new int[2 * MAX_E],
next = new int[2 * MAX_E];
last = new int[MAX_V], q = new int[MAX_V], dist = new int[MAX_V],
now = new int[MAX_V];
fill(last, last + MAX_V, -1);
}
void clear() {
fill(last, last + MAX_V, -1);
E = 0;
}
void add_edge(int u, int v, int uv, int vu = 0) {
to[E] = v, cap[E] = uv, next[E] = last[u];
last[u] = E++;
to[E] = u, cap[E] = vu, next[E] = last[v];
last[v] = E++;
}
bool bfs() {
fill(dist, dist + MAX_V, -1);
head = tail = 0;
q[tail] = t;
++tail;
dist[t] = 0;
while (head < tail) {
int v = q[head];
++head;
for (int e = last[v]; e != -1; e = next[e]) {
if (cap[e ^ 1] > 0 && dist[to[e]] == -1) {
q[tail] = to[e];
++tail;
dist[to[e]] = dist[v] + 1;
}
}
}
return dist[s] != -1;
}
int dfs(int v, int f) {
if (v == t) return f;
for (int &e = now[v]; e != -1; e = next[e]) {
if (cap[e] > 0 && dist[to[e]] == dist[v] - 1) {
int ret = dfs(to[e], min(f, cap[e]));
if (ret > 0) {
cap[e] -= ret;
cap[e ^ 1] += ret;
return ret;
}
}
}
return 0;
}
long long max_flow(int source, int sink) {
s = source;
t = sink;
long long f = 0;
int x;
while (bfs()) {
for (int i = 0; i < MAX_V; ++i) now[i] = last[i];
while (true) {
x = dfs(s, INT_MAX);
if (x == 0) break;
f += x;
}
}
return f;
}
};
int w[7], npv[40];
vector<int> mopper;
vector<pair<pair<int, int>, int> > vs;
vector<string> sol[40];
int main() {
int V, E, u, v, c;
map<string, int> has;
map<int, string> rhas;
string tmp;
has["S"] = 1;
has["M"] = 2;
has["L"] = 3;
has["XL"] = 4;
has["XXL"] = 5;
has["XXXL"] = 6;
rhas[1] = "S";
rhas[2] = "M";
rhas[3] = "L";
rhas[4] = "XL";
rhas[5] = "XXL";
rhas[6] = "XXXL";
for (int i = 1; i <= 6; i++) {
cin >> w[i];
}
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string tmp, a, b;
cin >> tmp;
int coun = 0;
for (int j = 0; j < tmp.size(); j++) {
if (tmp[j] == ',') {
coun++;
} else if (coun == 0) {
a.push_back(tmp[j]);
} else
b.push_back(tmp[j]);
}
if (coun == 0) {
npv[has[a]]++;
mopper.push_back(has[a]);
} else {
if (has[a] > has[b]) swap(a, b);
npv[has[a] * 6 + has[b]]++;
mopper.push_back(has[a] * 6 + has[b]);
}
}
for (int i = 0; i < n; i++) {
}
for (int i = 1; i <= 6; i++) {
vs.push_back(make_pair(make_pair(0, i), w[i]));
}
for (int i = 1; i <= 6; i++) {
vs.push_back(make_pair(make_pair(i, i + 6), w[i]));
vs.push_back(make_pair(make_pair(i + 6, 59), npv[i]));
}
for (int i = 1; i <= 6; i++) {
for (int j = i + 1; j <= 6; j++) {
vs.push_back(make_pair(make_pair(i, i * 6 + j + 6), w[i]));
vs.push_back(make_pair(make_pair(j, i * 6 + j + 6), w[j]));
}
}
for (int i = 1; i <= 6; i++) {
for (int j = i + 1; j <= 6; j++) {
vs.push_back(make_pair(make_pair(i * 6 + j + 6, 59), npv[i * 6 + j]));
}
}
flow_graph G(100, vs.size() + 1);
for (int i = 0; i < vs.size(); i++) {
if (vs[i].second) {
G.add_edge(vs[i].first.first, vs[i].first.second, vs[i].second, 0);
}
}
int ff = G.max_flow(0, 59), sumd = 0;
if (ff >= n) {
cout << "YES\n";
for (int i = 0; i < G.E; i += 2) {
int u = G.to[i], v = G.to[i + 1];
swap(u, v);
if (u >= 1 && u <= 6 && v >= 7 && v <= 42) {
int del = w[u] - G.cap[i];
while (del >= 1) {
sol[v - 6].push_back(rhas[u]);
del--;
}
}
}
for (int i = 0; i < n; i++) {
cout << sol[mopper[i]].back() << endl;
sol[mopper[i]].pop_back();
}
} else
cout << "NO\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
struct d_ {
template <typename T>
d_& operator,(const T& x) {
cerr << ' ' << x;
return *this;
}
template <typename T>
d_& operator,(const vector<T>& x) {
for (auto x : x) cerr << ' ' << x;
return *this;
}
} d_t;
vector<string> sh = {"S", "M", "L", "XL", "XXL", "XXXL"};
int main(void) {
ios_base::sync_with_stdio(false);
vll v(6);
for (ll i(0); i < 6; i++) cin >> v[i];
ll n;
cin >> n;
vector<queue<ll>> q(6), q2(6);
for (ll i(0); i < n; i++) {
string cur;
cin >> cur;
ll pos;
if ((pos = cur.find(",")) != string::npos) cur = cur.substr(0, pos);
ll curi = find(begin(sh), end(sh), cur) - sh.begin();
if (pos != string::npos)
q2[curi].push(i);
else
q[curi].push(i);
}
vll ret(n);
ll done = 0;
for (ll i(0); i < 6; i++) {
while (i && q2[i - 1].size() && v[i]) {
auto cur = q2[i - 1].front();
q2[i - 1].pop();
v[i]--;
ret[cur] = i;
done++;
}
while (q[i].size() && v[i]) {
auto cur = q[i].front();
q[i].pop();
v[i]--;
ret[cur] = i;
done++;
}
while (i < 5 && q2[i].size() && v[i]) {
auto cur = q2[i].front();
q2[i].pop();
v[i]--;
ret[cur] = i;
done++;
}
}
if (done != n)
cout << "NO" << endl;
else {
cout << "YES" << endl;
for (ll i(0); i < n; i++) cout << sh[ret[i]] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int get(string s) {
if (s == "S") return 1;
if (s == "M") return 2;
if (s == "L") return 3;
if (s == "XL") return 4;
if (s == "XXL") return 5;
if (s == "XXXL") return 6;
}
void rev(int x) {
if (x == 1) puts("S");
if (x == 2) puts("M");
if (x == 3) puts("L");
if (x == 4) puts("XL");
if (x == 5) puts("XXL");
if (x == 6) puts("XXXL");
}
struct Dinic {
int V, E, s, t, head[400100], work[400100], dis[400100];
int qf, qb, q[400100], to[4000200], cap[4000200], nxt[4000200];
void init(int n, int S, int T) {
s = S, t = T;
V = E = n + 1;
while (head[--E] = -1, E)
;
}
void add(int u, int v, int f) {
cap[E] = f, to[E] = v, nxt[E] = head[u], head[u] = E++;
cap[E] = 0, to[E] = u, nxt[E] = head[v], head[v] = E++;
}
bool bfs() {
int u, v, e = V + (qb = 1);
while (dis[--e] = -1, e)
;
for (q[qf = dis[s] = 0] = s; qf < qb && !~dis[t];)
for (e = head[u = q[qf++]]; ~e; e = nxt[e])
if (cap[e] && !~dis[v = to[e]]) dis[q[qb++] = v] = dis[u] + 1;
return ~dis[t];
}
int dfs(int u, int &b) {
if (u == t) return b;
for (int &e = work[u], v, c; ~e; e = nxt[e])
if ((c = cap[e]) && dis[v = to[e]] == dis[u] + 1)
if (v = dfs(v, c = min(b, c))) {
cap[e] -= v, cap[e ^ 1] += v, b = c;
return v;
}
return 0;
}
int dinic() {
int ans = 0, x;
while (bfs())
for (memcpy(work, head, V << 2); x = dfs(s, x = 0x3f3f3f3f);) ans += x;
return ans;
}
} dinic;
int num[400100];
char s[400100];
string st;
int main() {
for (int i = 1; i <= 6; i++) scanf("%d", num + i);
int n;
scanf("%d", &n);
dinic.init(n + 8, n + 7, n + 8);
for (int i = 1; i <= n; i++) {
scanf("%s", s);
int len = strlen(s), flag = 1;
for (int j = 0; j < len; j++)
if (s[j] == ',') {
flag = 0;
st.clear();
for (int k = 0; k < j; k++) st.push_back(s[k]);
int u = get(st);
dinic.add(i, n + u, 1);
st.clear();
for (int k = j + 1; k < len; k++) st.push_back(s[k]);
u = get(st);
dinic.add(i, n + u, 1);
}
if (flag) {
st.clear();
for (int j = 0; j < len; j++) st.push_back(s[j]);
int u = get(st);
dinic.add(i, n + u, 1);
}
}
for (int i = 1; i <= n; i++) dinic.add(n + 7, i, 1);
for (int i = 1; i <= 6; i++) dinic.add(n + i, n + 8, num[i]);
if (dinic.dinic() == n) {
puts("YES");
for (int u = 1; u <= n; u++) {
for (int e = dinic.head[u]; ~e; e = dinic.nxt[e]) {
int v = dinic.to[e];
if (n + 1 <= v && v <= n + 6 && dinic.cap[e ^ 1]) {
rev(v - n);
break;
}
}
}
} else
puts("NO");
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[100], n, j, i = -1, f;
string s;
vector<pair<pair<long long, long long>, long long> > v;
string ans[100003];
string rsiz(long long x) {
if (x == 0) return "S";
if (x == 1) return "M";
if (x == 2) return "L";
if (x == 3) return "XL";
if (x == 4) return "XXL";
if (x == 5) return "XXXL";
}
long long siz(string s) {
if (s == "S") return 0;
if (s == "M") return 1;
if (s == "L") return 2;
if (s == "XL") return 3;
if (s == "XXL") return 4;
if (s == "XXXL") return 5;
}
int main() {
for (int i = 0; i < 6; i++) cin >> a[i];
cin >> n;
f = n;
while (n--) {
i++;
cin >> s;
string s1, s2 = "";
j = 0;
for (; j < s.size() && s[j] != ','; j++) s1 += s[j];
j++;
for (; j < s.size() && s[j] != ','; j++) s2 += s[j];
long long x = siz(s1);
if (s2 == "") {
if (!a[x]) {
puts("NO");
return 0;
}
ans[i] = s1;
a[x]--;
continue;
}
long long y = siz(s2);
v.push_back({{x, y}, i});
}
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++) {
long long x = v[i].first.first;
long long y = v[i].first.second;
long long id = v[i].second;
if (a[x]) {
ans[id] = rsiz(x);
a[x]--;
continue;
}
if (a[y]) {
ans[id] = rsiz(y);
a[y]--;
continue;
}
puts("NO");
return 0;
}
puts("YES");
for (int i = 0; i < f; i++) cout << ans[i] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
struct node {
int x, y, id, ans;
} a[MAXN];
int size[10];
char str[10][20] = {"S", "M", "L", "XL", "XXL", "XXXL"};
bool cmp(node a, node b) {
if (b.y == -1) return 0;
if (a.y == -1) return 1;
return a.x < b.x;
}
bool cmp2(node a, node b) { return a.id < b.id; }
int solve(char *s) {
for (int i = 0; i < 6; i++) {
if (strcmp(str[i], s) == 0) return i;
}
return -1;
}
int main() {
for (int i = 0; i < 6; i++) scanf("%d", &size[i]);
int n;
scanf("%d", &n);
char s[20], t1[20], t2[20];
for (int i = 0; i < n; i++) {
int k1 = 0, k2 = 0;
scanf("%s", s);
int l = strlen(s), j = 0;
for (; j < l; j++) {
if (s[j] == ',')
break;
else
t1[k1++] = s[j];
}
t1[k1] = '\0';
for (j++; j < l; j++) t2[k2++] = s[j];
t2[k2] = '\0';
a[i].x = solve(t1);
a[i].y = solve(t2);
if (a[i].y != -1 && a[i].x > a[i].y) swap(a[i].x, a[i].y);
a[i].id = i;
}
sort(a, a + n, cmp);
int i = 0;
bool flag = 1;
for (; i < n; i++) {
if (a[i].y == -1) {
a[i].ans = a[i].x, size[a[i].x]--;
if (size[a[i].x] < 0) {
flag = 0;
break;
}
} else
break;
}
for (i; i < n; i++) {
if (!flag) break;
if (size[a[i].x]) {
size[a[i].x]--;
a[i].ans = a[i].x;
} else if (a[i].y != -1 && size[a[i].y]) {
size[a[i].y]--;
a[i].ans = a[i].y;
} else
flag = 0;
}
if (!flag)
puts("NO");
else {
puts("YES");
sort(a, a + n, cmp2);
for (int i = 0; i < n; i++) printf("%s\n", str[a[i].ans]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int> > a[100005];
int size[10];
int ans[100005];
string s;
bool cmp(int x, int y) {
if (a[x].first != a[y].first)
return a[x].first < a[y].first;
else
return a[x].second <= a[y].second;
}
string print(int x) {
if (x == 1) return "S\n";
if (x == 2) return "M\n";
if (x == 3) return "L\n";
if (x == 4) return "XL\n";
return x == 5 ? "XXL\n" : "XXXL\n";
}
void convert(int x) {
int i = 0;
int cnt = 0;
while (s[i] != ',' && s[i]) {
if (s[i] == 'S' || s[i] == 'X')
cnt++;
else if (s[i] == 'M')
cnt += 2;
else
cnt += 3;
i++;
}
if (!s[i]) {
a[x] = {-1, {cnt, a[x].second.second}};
return;
} else
a[x].first = cnt;
cnt = 0, i++;
while (s[i]) {
if (s[i] == 'S' || s[i] == 'X')
cnt++;
else if (s[i] == 'M')
cnt += 2;
else
cnt += 3;
i++;
}
a[x].second.first = cnt;
}
int main() {
int n;
for (int i = 1; i <= 6; i++) scanf("%d", &size[i]);
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> s;
convert(i);
a[i].second.second = i;
}
stable_sort(a, a + n);
for (int i = 0; i < n; i++) {
if (a[i].first == -1) {
if (size[a[i].second.first])
size[a[i].second.first]--;
else {
printf("NO\n");
return 0;
}
continue;
}
if (size[a[i].first]) {
size[a[i].first]--;
a[i].second.first = -1;
} else if (size[a[i].second.first]) {
size[a[i].second.first]--;
a[i].first = -1;
} else {
printf("NO\n");
return 0;
}
}
printf("YES\n");
for (int i = 0; i < n; i++) {
if (a[i].first > 0)
ans[a[i].second.second] = a[i].first;
else
ans[a[i].second.second] = a[i].second.first;
}
for (int i = 0; i < n; i++) cout << print(ans[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
string mp[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int ans[MAXN], n, rem[10];
int a[MAXN], b[MAXN];
int find(string s) {
for (int i = 0; i < 6; i++)
if (mp[i] == s) return i;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
for (int i = 0; i < 6; i++) cin >> rem[i];
cin >> n;
for (int i = 0; i < n; i++) {
string s, t;
cin >> s;
a[i] = b[i] = -1;
for (int j = 0; j < s.size(); j++) {
if (s[j] == ',') {
a[i] = find(t);
t = "";
} else
t += s[j];
}
if (a[i] == -1)
a[i] = find(t);
else
b[i] = find(t);
}
memset(ans, -1, sizeof(ans));
for (int i = 0; i < n; i++)
if (b[i] == -1) {
rem[a[i]]--;
ans[i] = a[i];
if (rem[a[i]] < 0) {
cout << "NO\n";
return 0;
}
}
for (int i = 0; i < n; i++)
if (ans[i] == -1 && a[i] == 0) {
if (rem[a[i]])
rem[a[i]]--, ans[i] = a[i];
else
rem[b[i]]--, ans[i] = b[i];
if (rem[b[i]] < 0) {
cout << "NO\n";
return 0;
}
}
for (int i = 0; i < n; i++)
if (ans[i] == -1 && a[i] == 1) {
if (rem[a[i]])
rem[a[i]]--, ans[i] = a[i];
else
rem[b[i]]--, ans[i] = b[i];
if (rem[b[i]] < 0) {
cout << "NO\n";
return 0;
}
}
for (int i = 0; i < n; i++)
if (ans[i] == -1 && a[i] == 2) {
if (rem[a[i]])
rem[a[i]]--, ans[i] = a[i];
else
rem[b[i]]--, ans[i] = b[i];
if (rem[b[i]] < 0) {
cout << "NO\n";
return 0;
}
}
for (int i = 0; i < n; i++)
if (ans[i] == -1 && a[i] == 3) {
if (rem[a[i]])
rem[a[i]]--, ans[i] = a[i];
else
rem[b[i]]--, ans[i] = b[i];
if (rem[b[i]] < 0) {
cout << "NO\n";
return 0;
}
}
for (int i = 0; i < n; i++)
if (ans[i] == -1 && a[i] == 4) {
if (rem[a[i]])
rem[a[i]]--, ans[i] = a[i];
else
rem[b[i]]--, ans[i] = b[i];
if (rem[b[i]] < 0) {
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
for (int i = 0; i < n; i++) cout << mp[ans[i]] << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int kol[7];
string s;
int n;
bool used[100005];
int ans[100005];
int ff[100005];
int sss[100005];
inline int get(string x) {
if (x == "S")
return 1;
else if (x == "M")
return 2;
else if (x == "L")
return 3;
else if (x == "XL")
return 4;
else if (x == "XXL")
return 5;
else
return 6;
}
inline void no() {
cout << "NO";
exit(0);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for (int i = 1; i <= 6; ++i) cin >> kol[i];
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> s;
string f = "";
string ss = "";
bool t = false;
for (int j = 1; j <= s.size(); ++j)
if (s[j - 1] == ',') {
t = true;
} else {
if (t == false)
f += s[j - 1];
else
ss += s[j - 1];
}
if (t == false) {
int q = get(f);
used[i] = true;
ans[i] = q;
if (kol[q] == 0) no();
--kol[q];
continue;
}
ff[i] = get(f);
sss[i] = get(ss);
if (ff[i] > sss[i]) swap(ff[i], sss[i]);
}
for (int i = 1; i <= 6; ++i) {
for (int j = 1; j <= n; ++j)
if (kol[i] && used[j] == false && (ff[j] == i - 1 && sss[j] == i)) {
used[j] = true;
--kol[i];
ans[j] = i;
}
for (int j = 1; j <= n; ++j)
if (kol[i] && used[j] == false && (ff[j] == i && sss[j] == i + 1)) {
used[j] = true;
--kol[i];
ans[j] = i;
}
}
for (int i = 1; i <= n; ++i)
if (used[i] == false) no();
cout << "YES" << '\n';
for (int i = 1; i <= n; ++i)
if (ans[i] == 1)
cout << "S" << '\n';
else if (ans[i] == 2)
cout << "M" << '\n';
else if (ans[i] == 3)
cout << "L" << '\n';
else if (ans[i] == 4)
cout << "XL" << '\n';
else if (ans[i] == 5)
cout << "XXL" << '\n';
else if (ans[i] == 6)
cout << "XXXL" << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
double Fib(double x, double z);
string BinDec(unsigned long long x);
string StringInt(long long x);
unsigned long long StringInt(string x);
unsigned long long BinDec(string x);
unsigned long long POWMOD(unsigned long long x, unsigned long long y,
unsigned long long mod);
unsigned long long POWE(long long, long long);
int a[10] = {}, j, i, x, c = 0;
string z, b[100200];
void lol(string e, string ee, string aa) {
for (i = 0; i < x; i++) {
if (b[i] == aa) {
if (e == "S" && a[0] > 0) {
b[i] = e;
a[0]--;
continue;
} else if (e == "M" && a[1] > 0) {
b[i] = e;
a[1]--;
continue;
} else if (e == "L" && a[2] > 0) {
b[i] = e;
a[2]--;
continue;
} else if (e == "XL" && a[3] > 0) {
b[i] = e;
a[3]--;
continue;
} else if (e == "XXL" && a[4] > 0) {
b[i] = e;
a[4]--;
continue;
} else if (e == "XXXL" && a[5] > 0) {
b[i] = e;
a[5]--;
continue;
}
if (ee == "S" && a[0] > 0) {
b[i] = ee;
a[0]--;
continue;
} else if (ee == "M" && a[1] > 0) {
b[i] = ee;
a[1]--;
continue;
} else if (ee == "L" && a[2] > 0) {
b[i] = ee;
a[2]--;
continue;
} else if (ee == "XL" && a[3] > 0) {
b[i] = ee;
a[3]--;
continue;
} else if (ee == "XXL" && a[4] > 0) {
b[i] = ee;
a[4]--;
continue;
} else if (ee == "XXXL" && a[5] > 0) {
b[i] = ee;
a[5]--;
continue;
} else
c = 1;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
for (i = 0; i < 6; i++) cin >> a[i];
cin >> x;
for (i = 0; i < x; i++) cin >> b[i];
lol("S", "S", "S");
lol("M", "M", "M");
lol("L", "L", "L");
lol("XL", "XL", "XL");
lol("XXL", "XXL", "XXL");
lol("XXXL", "XXXL", "XXXL");
lol("S", "M", "S,M");
lol("M", "L", "M,L");
lol("L", "XL", "L,XL");
lol("XL", "XXL", "XL,XXL");
lol("XXL", "XXXL", "XXL,XXXL");
if (c)
cout << "NO";
else {
cout << "YES" << endl;
for (i = 0; i < x; i++) cout << b[i] << endl;
}
return 0;
}
double Fib(double x, double z) {
int i = 0;
double f = x, r = x, t;
for (i = 2; i < z; i++) {
t = f;
f += r;
r = t;
}
return f;
}
string BinDec(unsigned long long x) {
string z;
while (1) {
z += ((x % 3) + '0');
x /= 3;
if (x == 0) break;
}
while (1) {
if (z.size() == 30) break;
z += '0';
}
reverse(z.begin(), z.end());
return z;
}
unsigned long long BinDec(string x) {
long long i;
unsigned long long z = 1, a = 0;
for (i = x.size() - 1; i >= 0; i--) {
if (x[i] == '1') a += z;
if (x[i] == '2') a += (2 * z);
z *= 3;
}
return a;
}
unsigned long long StringInt(string x) {
unsigned long long z = 0, i;
for (i = 0; i < x.size(); i++) {
z *= 2;
z += (x[i] - '0');
}
return z;
}
string StringInt(long long x) {
string z;
while (x != 0) {
z += (x % 10 + '0');
x /= 10;
}
reverse(z.begin(), z.end());
return z;
}
unsigned long long POWMOD(unsigned long long base, unsigned long long exp,
unsigned long long mod) {
unsigned long long res = 1;
while (exp > 0) {
if (exp % 2 == 1) res = (res * base);
res %= mod;
exp /= 2;
base = (base * base);
base %= mod;
}
return res % mod;
}
unsigned long long POWE(long long base, long long exp) {
unsigned long long res = 1;
while (exp > 0) {
if (exp % 2 == 1) res = (res * base);
exp /= 2;
base = (base * base);
}
return res;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[7];
string ans[200005];
string str[] = {"S", "M", "L", "XL", "XXL", "XXXL",
"S,M", "M,L", "L,XL", "XL,XXL", "XXL,XXXL"};
vector<int> v[7];
int main() {
for (int i = 0; i <= 5; ++i) {
cin >> arr[i];
}
cin >> n;
for (int i = 1; i <= n; ++i) {
string s;
cin >> s;
for (int j = 0; j <= 10; ++j) {
if (j < 6) {
if (s == str[j]) {
--arr[j];
ans[i] = str[j];
}
} else {
if (s == str[j]) {
v[j - 6].push_back(i);
}
}
}
}
for (int i = 0; i <= 5; ++i) {
if (arr[i] < 0) {
cout << "NO";
return 0;
}
}
for (int j = 6; j <= 10; ++j) {
int sz = v[j - 6].size();
for (int i = 0; i <= sz - 1; ++i) {
if (arr[j - 6] > 0) {
--arr[j - 6];
ans[v[j - 6][i]] = str[j - 6];
} else if (arr[j + 1 - 6] > 0) {
--arr[j + 1 - 6];
ans[v[j - 6][i]] = str[j + 1 - 6];
} else {
cout << "NO";
return 0;
}
}
}
cout << "YES\n";
for (int i = 1; i <= n; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int mulmod(long long int a, long long int b, long long int m) {
long long int q =
(long long int)(((long double)a * (long double)b) / (long double)m);
long long int r = a * b - q * m;
if (r > m) r %= m;
if (r < 0) r += m;
return r;
}
template <typename T>
T MOD(T a, T b) {
return (a < b ? a : a % b);
}
template <typename T>
T expo(T e, T n) {
T x = 1, p = e;
while (n) {
if (n & 1) x = x * p;
p = p * p;
n >>= 1;
}
return x;
}
template <typename T>
T power(T e, T n, T m) {
T x = 1, p = e;
while (n) {
if (n & 1) x = mulmod(x, p, m);
p = mulmod(p, p, m);
n >>= 1;
}
return x;
}
template <typename T>
T gcd(T a, T b) {
if (a % b) return gcd(b, a % b);
return b;
}
template <typename T>
T lcm(T a, T b) {
return (a * (b / gcd(a, b)));
}
map<string, int> m;
map<int, string> p;
int a[7];
vector<pair<int, pair<int, int> > > need;
string ans[100005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
for (int i = 1; i <= 6; i++) {
cin >> a[i];
}
m["S"] = 1, m["M"] = 2, m["L"] = 3, m["XL"] = 4, m["XXL"] = 5, m["XXXL"] = 6;
for (auto &x : m) p[x.second] = x.first;
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
string x, y;
bool is = false;
for (char c : s) {
if (c == ',') {
is = true;
continue;
}
(is ? y : x) += c;
}
if (y == "") {
if (a[m[x]]) {
--a[m[x]];
ans[i] = x;
} else {
cout << "NO";
return 0;
}
} else {
if (m[x] > m[y]) swap(x, y);
need.push_back({m[x], {m[y], i}});
}
}
sort(need.begin(), need.end());
for (pair<int, pair<int, int> > x : need) {
if (a[x.first]) {
--a[x.first];
ans[x.second.second] = p[x.first];
} else if (a[x.second.first]) {
--a[x.second.first];
ans[x.second.second] = p[x.second.first];
} else {
cout << "NO";
return 0;
}
}
cout << "YES\n";
for (int i = 1; i <= n; i++) {
cout << ans[i] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, a[10], c[10], ans[100005];
pair<long long, long long> b[100005];
string s;
map<string, long long> m;
map<long long, string> M;
vector<long long> v;
vector<pair<pair<long long, long long>, long long> > w;
pair<long long, long long> fun(string s) {
for (__typeof(((long long)s.size())) i = (0); i < ((long long)s.size());
i++) {
if (s[i] == ',') return {m[s.substr(0, i)], m[s.substr(i + 1)]};
}
return {m[s], -1};
}
string fun2(long long x) { return M[x]; }
void solve() {
for (__typeof((7)) i = (1); i < (7); i++) cin >> a[i], c[i] = a[i] == 0;
cin >> n;
for (__typeof((n + 1)) i = (1); i < (n + 1); i++) {
cin >> s;
b[i] = fun(s);
if (b[i].second == -1) {
a[b[i].first]--;
ans[i] = 1;
if (a[b[i].first] < 0) {
cout << "NO"
<< "\n";
return;
};
if (a[b[i].first] == 0) c[b[i].first] = 1;
} else
v.push_back(i);
}
for (auto i : v) {
if (c[b[i].first] && c[b[i].second]) {
cout << "NO"
<< "\n";
return;
};
if (c[b[i].first]) {
a[b[i].second]--;
ans[i] = 2;
if (a[b[i].second] == 0) c[b[i].second] = 1;
continue;
}
if (c[b[i].second]) {
a[b[i].first]--;
ans[i] = 1;
if (a[b[i].first] == 0) c[b[i].first] = 1;
continue;
}
w.push_back({{b[i].first, b[i].second}, i});
}
sort((w).begin(), (w).end());
for (auto i : w) {
if (!c[i.first.first]) {
a[i.first.first]--;
if (a[i.first.first] == 0) c[i.first.first] = 1;
ans[i.second] = 1;
} else if (!c[i.first.second]) {
a[i.first.second]--;
if (a[i.first.second] == 0) c[i.first.second] = 1;
ans[i.second] = 2;
} else {
cout << "NO"
<< "\n";
return;
};
}
cout << "YES"
<< "\n";
for (__typeof((n + 1)) i = (1); i < (n + 1); i++) {
if (ans[i] == 1)
cout << fun2(b[i].first) << "\n";
else
cout << fun2(b[i].second) << "\n";
}
}
void prep() {
m["S"] = 1, m["M"] = 2, m["L"] = 3;
m["XL"] = 4, m["XXL"] = 5, m["XXXL"] = 6;
for (auto i : m) M[i.second] = i.first;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t = 1;
prep();
cout << fixed << setprecision(12);
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
int a[6];
const string bij[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
map<string, int> m;
int choice[100005];
vector<pair<int, int> > c[6];
int main() {
ios_base::sync_with_stdio(0);
int n;
string str;
for (int i = 0; i < 6; ++i) m[bij[i]] = i;
int tmp, cur;
string tm, tp;
int num = 0;
bool found;
while (cin >> a[0]) {
for (int i = 1; i < 6; ++i) cin >> a[i];
cin >> n;
num = 0;
memset(choice, -1, sizeof(choice));
for (int i = 0; i < n; ++i) {
cin >> str;
found = 0;
for (int i = 0; i < str.length(); ++i) {
if (str[i] == ',') {
tm = str.substr(0, i);
tp = str.substr(i + 1);
found = 1;
break;
}
}
if (found) {
tmp = m[tm];
c[tmp].push_back(make_pair(tmp, i));
c[m[tp]].push_back(make_pair(tmp, i));
} else {
tmp = m[str];
choice[i] = tmp;
a[tmp]--;
++num;
}
}
bool bad = 0;
for (int i = 0; i < 6; ++i) {
if (a[i] < 0) {
bad = 1;
break;
}
sort(c[i].begin(), c[i].end());
for (int j = 0; j < c[i].size() && a[i]; ++j) {
tmp = c[i][j].second;
if (choice[tmp] == -1) {
choice[tmp] = i;
--a[i];
++num;
}
}
}
if (!bad && num == n) {
cout << "YES\n";
for (int i = 0; i < n; ++i) cout << bij[choice[i]] << "\n";
} else
cout << "NO\n";
for (int i = 0; i < 6; ++i) c[i].clear();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a(6);
for (int i = 0; i < 6; i++) cin >> a[i];
int n;
cin >> n;
vector<int> ans(n);
vector<string> pa;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
pa.push_back(s);
s += ',';
if (s.find(',') == s.size() - 1)
if (s == "S,") {
ans[i] = 0;
a[0]--;
} else if (s == "M,") {
ans[i] = 1;
a[1]--;
} else if (s == "L,") {
ans[i] = 2;
a[2]--;
} else if (s[1] == 'L') {
ans[i] = 3;
a[3]--;
} else if (s[2] == 'L') {
ans[i] = 4;
a[4]--;
} else if (s[3] == 'L') {
ans[i] = 5;
a[5]--;
}
}
for (int i = 0; i < pa.size(); i++) {
if (pa[i] == "S,M")
if (a[0] > 0) {
a[0]--;
ans[i] = 0;
} else {
a[1]--;
ans[i] = 1;
}
}
for (int i = 0; i < pa.size(); i++) {
if (pa[i] == "M,L")
if (a[1] > 0) {
a[1]--;
ans[i] = 1;
} else {
a[2]--;
ans[i] = 2;
}
}
for (int i = 0; i < pa.size(); i++) {
if (pa[i] == "L,XL")
if (a[2] > 0) {
a[2]--;
ans[i] = 2;
} else {
a[3]--;
ans[i] = 3;
}
}
for (int i = 0; i < pa.size(); i++) {
if (pa[i] == "XL,XXL")
if (a[3] > 0) {
a[3]--;
ans[i] = 3;
} else {
a[4]--;
ans[i] = 4;
}
}
for (int i = 0; i < pa.size(); i++) {
if (pa[i] == "XXL,XXXL")
if (a[4] > 0) {
a[4]--;
ans[i] = 4;
} else {
a[5]--;
ans[i] = 5;
}
}
for (int i = 0; i < 6; i++)
if (a[i] < 0) {
cout << "NO";
return 0;
}
cout << "YES" << endl;
for (int i = 0; i < ans.size(); i++) {
if (ans[i] == 0)
cout << "S";
else if (ans[i] == 1)
cout << "M";
else if (ans[i] == 2)
cout << "L";
else if (ans[i] == 3)
cout << "XL";
else if (ans[i] == 4)
cout << "XXL";
else if (ans[i] == 5)
cout << "XXXL";
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, ts[7];
vector<int> dts[7];
string ans[100001], want;
bool can = true;
string conv(int x) {
if (x == 0) return ("S");
if (x == 1) return ("M");
if (x == 2) return ("L");
if (x == 3) return ("XL");
if (x == 4) return ("XXL");
if (x == 5) return ("XXXL");
}
int main() {
for (int i = 0; i < 6; ++i) cin >> ts[i];
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> want;
int len = want.length();
string pref = "";
bool g = false;
for (int j = 0; j < len; ++j) {
if (want[j] == ',') {
g = true;
if (pref == "S") dts[0].push_back(i);
if (pref == "M") dts[1].push_back(i);
if (pref == "L") dts[2].push_back(i);
if (pref == "XL") dts[3].push_back(i);
if (pref == "XXL") dts[4].push_back(i);
if (pref == "XXXL") dts[5].push_back(i);
}
pref = pref + want[j];
}
if (g == false) {
if (pref == "S") {
ans[i] = "S";
ts[0]--;
if (ts[0] < 0) can = false;
}
if (pref == "M") {
ans[i] = "M";
ts[1]--;
if (ts[1] < 0) can = false;
}
if (pref == "L") {
ans[i] = "L";
ts[2]--;
if (ts[2] < 0) can = false;
}
if (pref == "XL") {
ans[i] = "XL";
ts[3]--;
if (ts[3] < 0) can = false;
}
if (pref == "XXL") {
ans[i] = "XXL";
ts[4]--;
if (ts[4] < 0) can = false;
}
if (pref == "XXXL") {
ans[i] = "XXXL";
ts[5]--;
if (ts[5] < 0) can = false;
}
}
}
for (int i = 0; i < 5; ++i) {
if (can == false) break;
for (auto it = 0; it < dts[i].size(); ++it) {
if (ts[i] > 0) {
ans[dts[i][it]] = conv(i);
ts[i]--;
} else {
if (ts[i + 1] <= 0) {
can = false;
break;
} else {
ans[dts[i][it]] = conv(i + 1);
ts[i + 1]--;
}
}
}
}
if (can == true) {
cout << "YES" << endl;
for (int i = 0; i < n; ++i) cout << ans[i] << endl;
} else
cout << "NO";
return (0);
}
|
#include <bits/stdc++.h>
using namespace std;
int check(string s) {
if (s == "S") return 0;
if (s == "M") return 1;
if (s == "L") return 2;
if (s == "XL") return 3;
if (s == "XXL")
return 4;
else
return 5;
}
string check1(int s) {
if (s == 0) return "S";
if (s == 1) return "M";
if (s == 2) return "L";
if (s == 3) return "XL";
if (s == 4)
return "XXL";
else
return "XXXL";
}
int i, n, t[6], l, k, j;
string s, str[2], ans[100005];
vector<pair<int, int> > v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
for (i = 0; i < 6; i++) cin >> t[i];
cin >> n;
for (i = 0; i < n; i++) {
cin >> s;
l = s.length();
k = 0;
str[0] = "";
for (j = 0; j < l; j++) {
if (s[j] == ',') {
k++;
break;
}
str[k] += s[j];
}
if (k == 0) {
t[check(str[0])]--;
if (t[check(str[0])] < 0) {
cout << "NO\n";
return 0;
}
ans[i] = str[0];
} else {
v.push_back(make_pair(check(str[0]), i));
}
}
sort(v.begin(), v.end());
for (i = 0; i < v.size(); i++) {
if (t[v[i].first] > 0) {
t[v[i].first]--;
ans[v[i].second] = check1(v[i].first);
} else {
t[v[i].first + 1]--;
if (t[v[i].first + 1] < 0) {
cout << "NO\n";
return 0;
}
ans[v[i].second] = check1(v[i].first + 1);
}
}
cout << "YES\n";
for (i = 0; i < n; i++) cout << ans[i] << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MN = 2e5 + 5;
int am[6], t[100000], o[100000];
int hi(string s) {
if (s == "S") return 0;
if (s == "M") return 1;
if (s == "L") return 2;
if (s == "XL") return 3;
if (s == "XXL") return 4;
if (s == "XXXL") return 5;
}
string to[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
string ans[100000];
int main() {
int n, i, j;
for (i = 0; i < 6; i++) scanf("%d", am + i);
scanf("%d", &n);
for (i = 0; i < n; i++) {
string s;
cin >> s;
int pos = 999;
if (s.find_first_of(',') != string::npos) pos = s.find_first_of(',');
if (pos != 999) s = s.substr(0, pos);
if (pos != 999) o[i] = 1;
t[i] = hi(s);
}
for (i = 0; i < 6; i++) {
for (j = 0; j < n; j++) {
if (i == 0) break;
if (o[j] == 0) continue;
if (t[j] != i - 1) continue;
if (ans[j] != "") continue;
if (am[i] == 0) {
printf("NO");
return 0;
}
am[i]--;
ans[j] = to[i];
}
for (j = 0; j < n; j++) {
if (o[j]) continue;
if (t[j] != i) continue;
if (am[i] == 0) {
printf("NO");
return 0;
}
am[i]--;
ans[j] = to[i];
}
for (j = 0; j < n; j++) {
if (o[j] == 0) continue;
if (t[j] != i) continue;
if (am[i] == 0) continue;
if (ans[j] != "") continue;
am[i]--;
ans[j] = to[i];
}
}
printf("YES\n");
for (i = 0; i < n; i++) cout << ans[i] << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int> > G[1000000];
vector<int> R(100001);
map<int, int> V;
map<long long int, long long int> P;
queue<long long int> Q;
void bfs(long long int X, long long int t) {
if (V[X] == 2) {
Q.pop();
return;
}
V[X] = 2;
Q.pop();
for (unsigned int i = 0; i < G[X].size(); i++) {
if (V[G[X][i].second] == 0 && G[X][i].first != 0) {
V[G[X][i].second] = 1;
P[G[X][i].second] = X;
if (G[X][i].second == t) return;
Q.push(G[X][i].second);
}
}
while (!Q.empty()) {
if (V[t] != 1)
bfs(Q.front(), t);
else
return;
}
}
long long int update(long long int c, long long int p, long long int small) {
if (c == p)
return small;
else {
for (unsigned int i = 0; i < G[p].size(); i++) {
if (G[p][i].second == c) {
if (small > G[p][i].first) small = G[p][i].first;
small = update(p, P[p], small);
G[p][i].first -= small;
for (unsigned int j = 0; j < G[c].size(); j++) {
if (G[c][j].second == p) {
G[c][j].first += small;
break;
}
}
break;
}
}
return small;
}
}
long long int MaxFlow(long long int s, long long int t) {
long long int maxflow = 0;
do {
P.clear();
V.clear();
V[s] = 1;
P[s] = s;
while (!Q.empty()) {
Q.pop();
}
Q.push(s);
bfs(Q.front(), t);
if (V[t] == 0)
break;
else {
maxflow += update(t, P[t], 1000000);
}
} while (1);
return maxflow;
}
int main() {
long long int n;
long long int x;
int c, d;
string s, a;
for (int i = 1; i <= 6; i++) {
cin >> x;
G[100 + i].push_back(make_pair(x, 107));
G[107].push_back(make_pair(0, 100 + i));
}
G[0].push_back(make_pair(0, 1));
G[0].push_back(make_pair(0, 2));
G[0].push_back(make_pair(0, 3));
G[0].push_back(make_pair(0, 4));
G[0].push_back(make_pair(0, 5));
G[0].push_back(make_pair(0, 6));
G[0].push_back(make_pair(0, 12));
G[0].push_back(make_pair(0, 21));
G[0].push_back(make_pair(0, 23));
G[0].push_back(make_pair(0, 32));
G[0].push_back(make_pair(0, 34));
G[0].push_back(make_pair(0, 43));
G[0].push_back(make_pair(0, 45));
G[0].push_back(make_pair(0, 54));
G[0].push_back(make_pair(0, 56));
G[0].push_back(make_pair(0, 65));
G[1].push_back(make_pair(0, 101));
G[101].push_back(make_pair(0, 1));
G[2].push_back(make_pair(0, 102));
G[102].push_back(make_pair(0, 2));
G[3].push_back(make_pair(0, 103));
G[103].push_back(make_pair(0, 3));
G[4].push_back(make_pair(0, 104));
G[104].push_back(make_pair(0, 4));
G[5].push_back(make_pair(0, 105));
G[105].push_back(make_pair(0, 5));
G[6].push_back(make_pair(0, 106));
G[106].push_back(make_pair(0, 6));
G[12].push_back(make_pair(0, 101));
G[101].push_back(make_pair(0, 12));
G[12].push_back(make_pair(0, 102));
G[102].push_back(make_pair(0, 12));
G[21].push_back(make_pair(0, 101));
G[101].push_back(make_pair(0, 21));
G[21].push_back(make_pair(0, 102));
G[102].push_back(make_pair(0, 21));
G[23].push_back(make_pair(0, 102));
G[102].push_back(make_pair(0, 23));
G[23].push_back(make_pair(0, 103));
G[103].push_back(make_pair(0, 23));
G[32].push_back(make_pair(0, 102));
G[102].push_back(make_pair(0, 32));
G[32].push_back(make_pair(0, 103));
G[103].push_back(make_pair(0, 32));
G[34].push_back(make_pair(0, 103));
G[103].push_back(make_pair(0, 34));
G[34].push_back(make_pair(0, 104));
G[104].push_back(make_pair(0, 34));
G[43].push_back(make_pair(0, 103));
G[103].push_back(make_pair(0, 43));
G[43].push_back(make_pair(0, 104));
G[104].push_back(make_pair(0, 43));
G[45].push_back(make_pair(0, 104));
G[104].push_back(make_pair(0, 45));
G[45].push_back(make_pair(0, 105));
G[105].push_back(make_pair(0, 45));
G[54].push_back(make_pair(0, 104));
G[104].push_back(make_pair(0, 54));
G[54].push_back(make_pair(0, 105));
G[105].push_back(make_pair(0, 54));
G[56].push_back(make_pair(0, 105));
G[105].push_back(make_pair(0, 56));
G[56].push_back(make_pair(0, 106));
G[106].push_back(make_pair(0, 56));
G[65].push_back(make_pair(0, 105));
G[105].push_back(make_pair(0, 65));
G[65].push_back(make_pair(0, 106));
G[106].push_back(make_pair(0, 65));
cin >> n;
for (long long int i = 1; i <= n; i++) {
a = "";
x = 0;
c = d = 0;
cin >> s;
for (int j = 0; j < s.length(); j++) {
if (s[j] == ',') {
if (a.compare("S") == 0) {
x = x * 10 + 1;
}
if (a.compare("M") == 0) {
x = x * 10 + 2;
}
if (a.compare("L") == 0) {
x = x * 10 + 3;
}
if (a.compare("XL") == 0) {
x = x * 10 + 4;
}
if (a.compare("XXL") == 0) {
x = x * 10 + 5;
}
if (a.compare("XXXL") == 0) {
x = x * 10 + 6;
}
a = "";
} else {
a += s[j];
}
}
if (a.compare("S") == 0) {
x = x * 10 + 1;
}
if (a.compare("M") == 0) {
x = x * 10 + 2;
}
if (a.compare("L") == 0) {
x = x * 10 + 3;
}
if (a.compare("XL") == 0) {
x = x * 10 + 4;
}
if (a.compare("XXL") == 0) {
x = x * 10 + 5;
}
if (a.compare("XXXL") == 0) {
x = x * 10 + 6;
}
c = x % 10;
d = x / 10;
for (int j = 0; j < G[x].size(); j++) {
if ((100 + c) == G[x][j].second || (d + 100) == G[x][j].second) {
G[x][j].first++;
}
}
R[i] = x;
for (int j = 0; j < G[0].size(); j++) {
if (G[0][j].second == x) G[0][j].first++;
}
}
long long int b = MaxFlow(0, 107);
int y;
int z;
if (b == n) {
cout << "YES" << endl;
for (long long int i = 1; i <= n; i++) {
for (int j = 0; j < G[R[i]].size(); j++) {
y = G[R[i]][j].second;
for (z = 0; z < G[y].size(); z++) {
if (G[y][z].second == R[i]) break;
}
if (G[y][z].first > 0) {
if (y == 101) {
cout << "S" << endl;
G[y][z].first--;
}
if (y == 102) {
cout << "M" << endl;
G[y][z].first--;
}
if (y == 103) {
cout << "L" << endl;
G[y][z].first--;
}
if (y == 104) {
cout << "XL" << endl;
G[y][z].first--;
}
if (y == 105) {
cout << "XXL" << endl;
G[y][z].first--;
}
if (y == 106) {
cout << "XXXL" << endl;
G[y][z].first--;
}
break;
}
}
}
} else {
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
char ss[][10] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int ind(char *t) {
int i;
for (i = 0; i < 6; i++)
if (strncmp(t, ss[i], strlen(ss[i])) == 0) break;
return i;
}
struct tshirt {
int i, j;
} tt[100000];
int compare(const void *a, const void *b) {
struct tshirt *pa = (struct tshirt *)a;
struct tshirt *pb = (struct tshirt *)b;
return pa->i - pb->i;
}
int main() {
int i, k, n, yes;
static char s[10], t[100000][10];
static int cnt[6];
for (i = 0; i < 6; i++) scanf("%d", &cnt[i]);
scanf("%d", &n);
yes = 1;
k = 0;
for (i = 0; i < n; i++) {
int j, l, two;
scanf("%s", s);
l = strlen(s);
two = 0;
for (j = 0; j < l; j++)
if (s[j] == ',') {
two = 1;
break;
}
if (!two) {
j = ind(s);
if (cnt[j] == 0) {
yes = 0;
break;
}
strcpy(t[i], s);
cnt[j]--;
} else {
tt[k].i = ind(s);
tt[k++].j = i;
}
}
if (yes) {
int i;
qsort(tt, k, sizeof(*tt), compare);
for (i = 0; i < k; i++)
if (cnt[tt[i].i] > 0) {
cnt[tt[i].i]--;
strcpy(t[tt[i].j], ss[tt[i].i]);
} else if (tt[i].i + 1 < 6 && cnt[tt[i].i + 1] > 0) {
cnt[tt[i].i + 1]--;
strcpy(t[tt[i].j], ss[tt[i].i + 1]);
} else {
yes = 0;
break;
}
}
printf("%s\n", yes ? "YES" : "NO");
if (yes)
for (i = 0; i < n; i++) printf("%s\n", t[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long i, j, n, t, k, d, b[100009], c[100009], y[100009], f[10];
string s[100009], ss, a[100009], x[100009], e[100009];
map<string, long long> mp;
vector<long long> v[100];
int main() {
string name[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
for (i = 0; i < 6; i++) mp[name[i]] = i;
for (i = 1; i <= 6; i++) cin >> c[i];
cin >> n;
for (i = 1; i <= n; i++) {
cin >> s[i];
d = 1;
ss = "";
for (j = 0; j < s[i].length(); j++) {
if (s[i][j] == ',') {
d = 0;
break;
}
ss = ss + s[i][j];
}
if (d) {
t++;
a[t] = ss;
b[t] = i;
} else
v[mp[ss]].push_back(i);
}
for (i = 0; i < 6; i++) f[mp[name[i]]] += c[i + 1];
for (i = 1; i <= t; i++) {
e[b[i]] = a[i];
f[mp[a[i]]]--;
}
for (i = 0; i < 6; i++) {
vector<long long>::iterator it;
for (it = v[i].begin(); it != v[i].end(); ++it) {
if (f[mp[name[i]]] <= 0) {
if (f[mp[name[i]] + 1] <= 0) {
cout << "NO";
return 0;
}
f[mp[name[i]] + 1]--;
e[*it] = name[mp[name[i]] + 1];
} else
f[mp[name[i]]]--, e[*it] = name[mp[name[i]]];
}
}
bool ok = 1;
for (i = 0; i < 6; i++)
if (f[mp[name[i]]] < 0) ok = 0;
if (ok) {
cout << "YES" << endl;
for (i = 1; i <= n; i++) cout << e[i] << endl;
} else
cout << "NO";
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int num[7];
int need[maxn];
int ans[maxn];
map<string, int> mp;
map<int, string> out;
int n;
char c[20];
bool flag = 1;
int main() {
mp["S"] = 1;
mp["M"] = 2;
mp["L"] = 3;
mp["XL"] = 4;
mp["XXL"] = 5;
mp["XXXL"] = 6;
mp["S,M"] = 7;
mp["M,L"] = 8;
mp["L,XL"] = 9;
mp["XL,XXL"] = 10;
mp["XXL,XXXL"] = 11;
out[1] = "S";
out[2] = "M";
out[3] = "L";
out[4] = "XL";
out[5] = "XXL";
out[6] = "XXXL";
for (int i = 1; i <= 6; i++) cin >> num[i];
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%s", c);
need[i] = mp[c];
}
for (int i = 1; i <= n; i++) {
if (need[i] >= 1 && need[i] <= 6) {
if (num[need[i]] > 0) {
num[need[i]]--;
ans[i] = need[i];
} else {
flag = 0;
break;
}
}
}
if (!flag) {
cout << "NO" << endl;
return 0;
}
for (int i = 1; i <= n; i++) {
if (need[i] == 7) {
if (num[1] > 0) {
num[1]--;
ans[i] = 1;
} else if (num[2] > 0) {
num[2]--;
ans[i] = 2;
} else {
flag = 0;
break;
}
}
}
if (!flag) {
cout << "NO" << endl;
return 0;
}
for (int i = 1; i <= n; i++) {
if (need[i] == 8) {
if (num[2] > 0) {
num[2]--;
ans[i] = 2;
} else if (num[3] > 0) {
num[3]--;
ans[i] = 3;
} else {
flag = 0;
break;
}
}
}
if (!flag) {
cout << "NO" << endl;
return 0;
}
for (int i = 1; i <= n; i++) {
if (need[i] == 9) {
if (num[3] > 0) {
num[3]--;
ans[i] = 3;
} else if (num[4] > 0) {
num[4]--;
ans[i] = 4;
} else {
flag = 0;
break;
}
}
}
if (!flag) {
cout << "NO" << endl;
return 0;
}
for (int i = 1; i <= n; i++) {
if (need[i] == 10) {
if (num[4] > 0) {
num[4]--;
ans[i] = 4;
} else if (num[5] > 0) {
num[5]--;
ans[i] = 5;
} else {
flag = 0;
break;
}
}
}
if (!flag) {
cout << "NO" << endl;
return 0;
}
for (int i = 1; i <= n; i++) {
if (need[i] == 11) {
if (num[5] > 0) {
num[5]--;
ans[i] = 5;
} else if (num[6] > 0) {
num[6]--;
ans[i] = 6;
} else {
flag = 0;
break;
}
}
}
if (!flag) {
cout << "NO" << endl;
return 0;
} else {
cout << "YES" << endl;
for (int i = 1; i <= n; i++) printf("%s\n", out[ans[i]].c_str());
}
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> x;
struct u {
int a, b, n;
};
int main() {
long long i, j, l, m, n, k[10] = {0};
string s;
u a[200001];
vector<string> ot;
for (i = 0; i < 6; i++) cin >> k[i];
ot.push_back("S");
ot.push_back("M");
ot.push_back("L");
ot.push_back("XL");
ot.push_back("XXL");
ot.push_back("XXXL");
cin >> n;
getline(cin, s);
for (i = 0; i < n; i++) {
a[i].b = -1;
getline(cin, s);
string s1;
j = 0;
while (j < s.length()) {
if (s[j] != ',')
s1 = s1 + s[j];
else {
int i1 = 0;
while (ot[i1] != s1) i1++;
a[i].b = i1;
s1 = "";
}
j++;
}
int i1 = 0;
while (ot[i1] != s1) i1++;
a[i].a = i1;
}
for (i = 0; i < n; i++) {
a[i].n = -1;
if (a[i].b == -1) {
a[i].n = 1;
k[a[i].a]--;
}
}
for (i = 5; i >= 0; i--)
for (j = 0; j < n; j++)
if (a[j].n == -1) {
if (a[j].a == i) {
a[j].n = 1;
if (k[a[j].a] > 0) {
k[a[j].a]--;
a[j].b = -1;
} else {
a[j].a = a[j].b;
a[j].b = -1;
k[a[j].a]--;
}
}
}
for (i = 0; i <= 5; i++)
if (k[i] < 0) {
cout << "NO";
return 0;
}
cout << "YES" << endl;
for (i = 0; i < n; i++) cout << ot[a[i].a] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char str[1000];
char temp[1000];
const char *ts(int n) {
if (n == 0) return "S";
if (n == 1) return "M";
if (n == 2) return "L";
if (n == 3) return "XL";
if (n == 4) return "XXL";
if (n == 5)
return "XXXL";
else
return "WA merecido";
}
int getcode(const char *s) {
int a = 0;
if (strcmp(s, "S") == 0) return a;
a++;
if (strcmp(s, "M") == 0) return a;
a++;
if (strcmp(s, "L") == 0) return a;
a++;
if (strcmp(s, "XL") == 0) return a;
a++;
if (strcmp(s, "XXL") == 0) return a;
a++;
if (strcmp(s, "XXXL") == 0) return a;
return -1;
}
int main() {
map<int, set<int> > ends;
map<int, set<int> > isin;
map<int, int> tshirts;
int val[6];
int n;
for (int i = 0; i < 6; i++) {
scanf("%d", &val[i]);
}
scanf("%d", &n);
getchar();
for (int i = 0; i < n; i++) {
tshirts[i] = -1;
scanf("%s", str);
int pos = 0;
int pastCode = -1;
for (int j = 0; j < strlen(str); j++) {
if (str[j] != ',') {
temp[pos++] = str[j];
} else {
temp[pos] = '\0';
pos = 0;
pastCode = getcode(temp);
}
}
temp[pos] = '\0';
int code = getcode(temp);
if (pastCode != -1) {
isin[pastCode].insert(i);
}
isin[code].insert(i);
ends[code].insert(i);
}
bool can = true;
for (int i = 0; i < 6; i++) {
if (val[i] >= ends[i].size()) {
while (ends[i].size()) {
int t = *(ends[i].begin());
if (tshirts[t] == -1) {
val[i]--;
tshirts[t] = i;
}
ends[i].erase(t);
isin[i].erase(t);
}
while (val[i] && isin[i].size()) {
int t = *(isin[i].begin());
if (tshirts[t] == -1) {
val[i]--;
tshirts[t] = i;
}
ends[i + 1].erase(t);
isin[i].erase(t);
}
} else {
can = false;
break;
}
}
if (can) {
printf("YES\n");
for (int i = 0; i < n; i++) {
printf("%s\n", ts(tshirts[i]));
}
} else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 22;
int n;
string str[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int ans[N], val[N];
vector<int> vec[7];
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int x, y;
for (int i = 0; i < (6); i++) cin >> val[i];
cin >> n;
for (int i = 0; i < (n); i++) {
string s;
x = -1;
cin >> s;
for (int j = 0; j < (s.size()); j++) {
if (s[j] == ',') x = j;
}
if (x == -1) {
for (int j = 0; j < (6); j++) {
if (str[j] == s) {
if (!val[j]) {
cout << "NO";
return 0;
}
val[j]--;
ans[i] = j;
}
}
} else {
for (int j = 0; j < (6); j++) {
if (str[j] == s.substr(0, x)) vec[j].push_back(i);
}
}
}
for (int i = 0; i < (5); i++) {
if (val[i] >= vec[i].size()) {
for (int j = 0; j < (vec[i].size()); j++) ans[vec[i][j]] = i;
} else {
for (int j = 0; j < (val[i]); j++) ans[vec[i][j]] = i;
if (vec[i].size() - val[i] > val[i + 1]) {
cout << "NO";
return 0;
}
val[i + 1] -= vec[i].size() - val[i];
for (int j = val[i]; j < vec[i].size(); j++) ans[vec[i][j]] = i + 1;
}
}
cout << "YES" << endl;
for (int i = 0; i < (n); i++) cout << str[ans[i]] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
string sz[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int d[6], an[SIZE];
vector<int> p[5];
int main() {
for (int i = 0; i < (6); ++i) scanf("%d", &(d[i]));
int(n);
scanf("%d", &n);
for (int i = 0; i < (n); ++i) {
string s;
cin >> s;
bool done = 0;
for (int j = 0; j < (6); ++j) {
if (s == sz[j]) {
an[i] = j;
d[j]--;
if (d[j] < 0) return 0 * puts("NO");
done = 1;
break;
}
}
if (!done) {
for (int j = 0; j < (6); ++j) {
if (s.substr(0, ((int)(sz[j]).size())) == sz[j]) {
p[j].push_back(i);
break;
}
}
}
}
for (int i = 0; i < (5); ++i) {
for (int j = 0; j < (((int)(p[i]).size())); ++j) {
if (d[i] == 0 && d[i + 1] == 0) return 0 * puts("NO");
if (d[i]) {
d[i]--;
an[p[i][j]] = i;
} else {
d[i + 1]--;
an[p[i][j]] = i + 1;
}
}
}
puts("YES");
for (int i = 0; i < (n); ++i) cout << sz[an[i]] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string sizes[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
map<string, int> ind;
for (int i = 0; i < 6; i++) {
ind[sizes[i]] = i;
}
vector<int> cnt(6);
for (int i = 0; i < 6; i++) {
cin >> cnt[i];
}
int n;
cin >> n;
vector<string> ans(n);
vector<vector<int>> mids(6);
for (int i = 0; i < n; i++) {
string sz;
cin >> sz;
if (ind.count(sz)) {
int id = ind[sz];
if (cnt[id] == 0) {
cout << "NO" << endl;
return 0;
}
ans[i] = sz;
cnt[id]--;
} else {
string sz1;
int j = 0;
while (sz[j] != ',') {
sz1.push_back(sz[j]);
j++;
}
int i1 = ind[sz1];
mids[i1].push_back(i);
}
}
for (int i = 0; i < 6; i++) {
while (i > 0 && mids[i - 1].size() > 0) {
ans[mids[i - 1].back()] = sizes[i];
cnt[i]--;
mids[i - 1].pop_back();
}
if (cnt[i] < 0) {
cout << "NO" << endl;
return 0;
}
while (i < 6 && cnt[i] > 0 && mids[i].size() > 0) {
ans[mids[i].back()] = sizes[i];
cnt[i]--;
mids[i].pop_back();
}
}
for (int i = 0; i < 6; i++) {
if (mids[i].size() > 0) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
for (auto s : ans) {
cout << s << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, m, l, xl, xxl, xxxl;
cin >> s >> m >> l >> xl >> xxl >> xxxl;
int n;
cin >> n;
int sm = 0, ml = 0, lxl = 0, xlxxl = 0, xxlxxxl = 0;
pair<int, int> arr[7];
vector<string> vt;
for (int i = 1; i <= n; i++) {
string ss;
cin >> ss;
vt.push_back(ss);
if (ss == "S")
s--;
else if (ss == "M")
m--;
else if (ss == "L")
l--;
else if (ss == "XL")
xl--;
else if (ss == "XXL")
xxl--;
else if (ss == "XXXL")
xxxl--;
else if (ss == "S,M")
sm++;
else if (ss == "M,L")
ml++;
else if (ss == "L,XL")
lxl++;
else if (ss == "XL,XXL")
xlxxl++;
else if (ss == "XXL,XXXL")
xxlxxxl++;
}
if (s < 0 || m < 0 || l < 0 || xl < 0 || xxl < 0 || xxxl < 0) {
cout << "NO" << endl;
return 0;
}
if (s <= sm) {
sm -= s;
arr[1].first = s;
if (sm > m) {
cout << "NO" << endl;
return 0;
}
arr[1].second = sm;
m -= sm;
} else {
arr[1].first = sm;
sm = 0;
arr[1].second = 0;
}
if (m <= ml) {
ml -= m;
arr[2].first = m;
if (ml > l) {
cout << "NO" << endl;
return 0;
}
arr[2].second = ml;
l -= ml;
} else {
arr[2].first = ml;
ml = 0;
arr[2].second = 0;
}
if (l <= lxl) {
lxl -= l;
arr[3].first = l;
if (lxl > xl) {
cout << "NO" << endl;
return 0;
}
arr[3].second = lxl;
xl -= lxl;
} else {
arr[3].first = lxl;
lxl = 0;
arr[3].second = 0;
}
if (xl <= xlxxl) {
xlxxl -= xl;
arr[4].first = xl;
if (xlxxl > xxl) {
cout << "NO" << endl;
return 0;
}
arr[4].second = xlxxl;
xxl -= xlxxl;
} else {
arr[4].first = xlxxl;
xlxxl = 0;
arr[4].second = 0;
}
if (xxl <= xxlxxxl) {
xxlxxxl -= xxl;
arr[5].first = xxl;
if (xxlxxxl > xxxl) {
cout << "NO" << endl;
return 0;
}
arr[5].second = xxlxxxl;
xxxl -= xxlxxxl;
} else {
arr[5].first = xxlxxxl;
xxlxxxl = 0;
arr[5].second = 0;
}
cout << "YES" << endl;
for (int i = 0; i < vt.size(); i++) {
if (vt[i] == "S" || vt[i] == "M" || vt[i] == "L" || vt[i] == "XL" ||
vt[i] == "XXL" || vt[i] == "XXXL")
cout << vt[i] << endl;
else if (vt[i] == "S,M") {
if (arr[1].first > 0) {
cout << "S" << endl;
arr[1].first--;
} else {
cout << "M" << endl;
arr[1].second--;
}
} else if (vt[i] == "M,L") {
if (arr[2].first > 0) {
cout << "M" << endl;
arr[2].first--;
} else {
cout << "L" << endl;
arr[2].second--;
}
} else if (vt[i] == "L,XL") {
if (arr[3].first > 0) {
cout << "L" << endl;
arr[3].first--;
} else {
cout << "XL" << endl;
arr[3].second--;
}
} else if (vt[i] == "XL,XXL") {
if (arr[4].first > 0) {
cout << "XL" << endl;
arr[4].first--;
} else {
cout << "XXL" << endl;
arr[4].second--;
}
} else if (vt[i] == "XXL,XXXL") {
if (arr[5].first > 0) {
cout << "XXL" << endl;
arr[5].first--;
} else {
cout << "XXXL" << endl;
arr[5].second--;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char s1[5][10] = {"S,M", "M,L", "L,XL", "XL,XXL", "XXL,XXXL"};
char s2[6][10] = {"S", "M", "L", "XL", "XXL", "XXXL"};
char s3[100005][10];
int cnt[6];
int main() {
for (int i = 0; i < 6; i++) cin >> cnt[i];
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s3[i]);
for (int j = 0; j < 6; j++) {
if (strcmp(s3[i], s2[j]) == 0) {
cnt[j]--;
break;
}
}
}
for (int i = 0; i < 6; i++) {
if (cnt[i] < 0) {
cout << "NO";
return 0;
}
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < n; j++) {
if (strcmp(s1[i], s3[j]) == 0) {
if (cnt[i] > 0) {
cnt[i]--;
strcpy(s3[j], s2[i]);
} else if (cnt[i + 1] > 0) {
cnt[i + 1]--;
strcpy(s3[j], s2[i + 1]);
} else {
cout << "NO" << endl;
return 0;
}
}
}
}
cout << "YES" << endl;
for (int i = 0; i < n; i++) cout << s3[i] << endl;
return 0;
}
|
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int a[10];
int n;
int dat[200000];
int ans[200000];
string tosize[10] = {"S", "M", "L", "XL", "XXL", "XXXL"};
map<string, int> toint;
int main() {
int i, j, k, l;
for (i = 0; i < 6; i++) cin >> a[i];
cin >> n;
for (i = 0; i < 6; i++) toint[tosize[i]] = i;
for (i = 0; i < n; i++) {
char in[20];
scanf("%s", in);
int len = strlen(in);
if (count(in, in + len, ',') == 0) {
dat[i] = toint[string(in)];
} else {
int x = find(in, in + len, ',') - in;
in[x] = 0;
dat[i] = toint[string(in)] + 6;
}
}
memset(ans, -1, sizeof(ans));
for (i = 0; i < n; i++) {
if (dat[i] < 6) {
a[dat[i]]--;
ans[i] = dat[i];
if (a[dat[i]] < 0) return !printf("NO");
}
}
for (i = 0; i < 6; i++) {
for (j = 0; j < n; j++) {
if (a[i] == 0) break;
if (ans[j] == -1 && dat[j] == i + 6 - 1) {
ans[j] = i;
a[i]--;
}
}
for (j = 0; j < n; j++) {
if (a[i] == 0) break;
if (ans[j] == -1 && dat[j] == i + 6) {
ans[j] = i;
a[i]--;
}
}
}
if (count(ans, ans + n, -1)) return !printf("NO");
printf("YES\n");
for (i = 0; i < n; i++) printf("%s\n", tosize[ans[i]].c_str());
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int D = 6;
string p[D] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int which(string s) {
for (int i = 0; i < D; i++)
if (p[i] == s) return i;
assert(false);
}
int cnt[D];
const int MX = 100 * 1000 + 999;
string ans[MX];
int n;
vector<int> pairs[D - 1];
bool solve() {
for (int i = 0; i < n; i++) {
string s;
cin >> s;
auto pos = s.find(',');
if (pos == string::npos) {
int idx = which(s);
if (cnt[idx] <= 0) return false;
cnt[idx]--;
ans[i] = s;
} else {
assert(s[pos] == ',');
s = s.substr(0, pos);
pairs[which(s)].push_back(i);
}
}
for (int i = 0; i < D - 1; i++) {
for (auto idx : pairs[i]) {
if (cnt[i] > 0) {
cnt[i]--;
ans[idx] = p[i];
} else if (cnt[i + 1] > 0) {
cnt[i + 1]--;
ans[idx] = p[i + 1];
} else
return false;
}
}
return true;
}
int main() {
for (int i = 0; i < D; i++) cin >> cnt[i];
cin >> n;
if (solve()) {
cout << "YES\n";
for (int i = 0; i < n; i++) cout << ans[i] << '\n';
} else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const string Sizes[] = {"S", "M", "L", "XL", "XXL", "XXXL",
"S,M", "M,L", "L,XL", "XL,XXL", "XXL,XXXL"};
int main() {
int Num[6], NPeople;
int Num_BU[6];
cin >> Num[0] >> Num[1] >> Num[2] >> Num[3] >> Num[4] >> Num[5];
cin >> NPeople;
for (int index = 0; index < 6; index++) {
Num_BU[index] = Num[index];
}
vector<int> Requests;
string strval;
for (int index = 0; index < NPeople; index++) {
cin >> strval;
for (int index2 = 0; index2 < 11; index2++) {
if (strval == Sizes[index2]) {
Requests.push_back(index2);
break;
}
}
}
int NumRequest;
int *Answer = new int[NPeople];
for (int index = 0; index < 6; index++) {
Num[index] -= count(Requests.begin(), Requests.end(), index);
if (Num[index] < 0) {
cout << "NO" << endl;
exit(0);
}
for (int index2 = 0; index2 < NPeople; index2++) {
if (Requests[index2] == index) {
Answer[index2] = index;
}
}
}
for (int index = 6; index < 11; index++) {
NumRequest = count(Requests.begin(), Requests.end(), index);
if (Num[(index - 6)] >= NumRequest) {
for (int index2 = 0; index2 < NPeople; index2++) {
if (Requests[index2] == index) {
Answer[index2] = index - 6;
}
}
} else {
for (int index2 = 0; index2 < NPeople; index2++) {
if (Requests[index2] == index && Num[index - 6] > 0) {
Answer[index2] = index - 6;
Num[index - 6]--;
} else if (Requests[index2] == index && Num[index - 5] > 0) {
Answer[index2] = index - 5;
Num[index - 5]--;
} else if (Requests[index2] == index && Num[index - 5] <= 0) {
cout << "NO" << endl;
exit(0);
}
}
}
}
cout << "YES" << endl;
for (int index = 0; index < NPeople; index++) {
cout << Sizes[Answer[index]] << endl;
}
delete[] Answer;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, s, m, l, xl, xxl, xxxl;
vector<long long> sr, mr, lr, xlr, xxlr, xxxlr;
string ans[100111];
string t;
int main() {
cin >> s >> m >> l >> xl >> xxl >> xxxl;
cin >> n;
for (long long i = 0; i < n; ++i) {
cin >> t;
if (t == "S") {
--s;
ans[i] = t;
} else if (t == "M") {
--m;
ans[i] = t;
} else if (t == "L") {
--l;
ans[i] = t;
} else if (t == "XL") {
--xl;
ans[i] = t;
} else if (t == "XXL") {
--xxl;
ans[i] = t;
} else if (t == "XXXL") {
--xxxl;
ans[i] = t;
} else if (t == "S,M") {
sr.push_back(i);
} else if (t == "M,L") {
mr.push_back(i);
} else if (t == "L,XL") {
lr.push_back(i);
} else if (t == "XL,XXL") {
xlr.push_back(i);
} else if (t == "XXL,XXXL") {
xxlr.push_back(i);
}
}
while (s > 0 && sr.size()) {
ans[sr[sr.size() - 1]] = "S";
sr.pop_back();
--s;
}
while (m > 0 && sr.size()) {
ans[sr[sr.size() - 1]] = "M";
sr.pop_back();
--m;
}
while (m > 0 && mr.size()) {
ans[mr[mr.size() - 1]] = "M";
mr.pop_back();
--m;
}
while (l > 0 && mr.size()) {
ans[mr[mr.size() - 1]] = "L";
mr.pop_back();
--l;
}
while (l > 0 && lr.size()) {
ans[lr[lr.size() - 1]] = "L";
lr.pop_back();
--l;
}
while (xl > 0 && lr.size()) {
ans[lr[lr.size() - 1]] = "XL";
lr.pop_back();
--xl;
}
while (xl > 0 && xlr.size()) {
ans[xlr[xlr.size() - 1]] = "XL";
xlr.pop_back();
--xl;
}
while (xxl > 0 && xlr.size()) {
ans[xlr[xlr.size() - 1]] = "XXL";
xlr.pop_back();
--xxl;
}
while (xxl > 0 && xxlr.size()) {
ans[xxlr[xxlr.size() - 1]] = "XXL";
xxlr.pop_back();
--xxl;
}
while (xxxl > 0 && xxlr.size()) {
ans[xxlr[xxlr.size() - 1]] = "XXXL";
xxlr.pop_back();
--xxxl;
}
while (xxxl > 0 && xxxlr.size()) {
ans[xxxlr[xxxlr.size() - 1]] = "XXXL";
xxxlr.pop_back();
--xxxl;
}
if (sr.size() || mr.size() || lr.size() || xlr.size() || xxlr.size() ||
xxxlr.size() || s < 0 || l < 0 || m < 0 || xl < 0 || xxl < 0 || xxxl < 0)
cout << "NO";
else {
cout << "YES";
for (long long i = 0; i < n; ++i) {
cout << '\n' << ans[i];
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, n, t;
bool fl, f;
string s;
vector<int> a;
vector<int> b(5);
vector<int> d(10);
for (int i = 0; i < 6; i++) {
cin >> k;
a.push_back(k);
}
cin >> n;
vector<int> c(n);
for (int i = 0; i < n; i++) {
cin >> s;
t = 0;
fl = false;
for (int j = 0; j < s.size(); j++) {
if (s[j] == ',') {
fl = true;
if (t == 'S') {
b[0]++;
c[i] = 7;
break;
}
if (t == 'M') {
b[1]++;
c[i] = 8;
break;
}
if (t == 'L') {
b[2]++;
c[i] = 9;
break;
}
if (t == 'X' + 'L') {
b[3]++;
c[i] = 10;
break;
}
b[4]++;
c[i] = 11;
break;
} else {
t += s[j];
}
}
if (!fl) {
if (t == 'S') {
a[0]--;
c[i] = 1;
} else {
if (t == 'M') {
a[1]--;
c[i] = 2;
} else {
if (t == 'L') {
a[2]--;
c[i] = 3;
} else {
if (t == 'X' + 'L') {
a[3]--;
c[i] = 4;
} else {
if (t == 'X' + 'X' + 'L') {
a[4]--;
c[i] = 5;
} else {
a[5]--;
c[i] = 6;
}
}
}
}
}
}
}
f = true;
for (int i = 0; i < 6; i++) {
if (a[i] < 0) {
f = false;
break;
} else {
if (i == 0) {
b[0] -= a[0];
d[0] = a[0];
} else {
if (i >= 1 && i < 5) {
a[i] -= max(b[i - 1], 0);
if (a[i] < 0) {
f = false;
break;
} else {
b[i] -= a[i];
d[2 * i] = a[i];
}
} else {
if (b[4] > a[5]) {
f = false;
break;
} else {
d[9] = a[5];
}
}
}
}
}
if (!f) {
cout << "NO";
} else {
cout << "YES\n";
for (int i = 0; i < n; i++) {
if (c[i] == 1) {
cout << "S\n";
continue;
}
if (c[i] == 2) {
cout << "M\n";
continue;
}
if (c[i] == 3) {
cout << "L\n";
continue;
}
if (c[i] == 4) {
cout << "XL\n";
continue;
}
if (c[i] == 5) {
cout << "XXL\n";
continue;
}
if (c[i] == 6) {
cout << "XXXL\n";
continue;
}
if (c[i] == 7) {
if (d[0] > 0) {
cout << "S\n";
d[0]--;
} else {
cout << "M\n";
}
continue;
}
if (c[i] == 8) {
if (d[2] > 0) {
cout << "M\n";
d[2]--;
} else {
cout << "L\n";
}
continue;
}
if (c[i] == 9) {
if (d[4] > 0) {
cout << "L\n";
d[4]--;
} else {
cout << "XL\n";
}
continue;
}
if (c[i] == 10) {
if (d[6] > 0) {
cout << "XL\n";
d[6]--;
} else {
cout << "XXL\n";
}
continue;
} else {
if (d[8] > 0) {
cout << "XXL\n";
d[8]--;
} else {
cout << "XXXL\n";
}
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int u, v;
long long cap, flow;
Edge() {}
Edge(int u, int v, long long cap) : u(u), v(v), cap(cap), flow(0) {}
};
struct Dinic {
int N;
vector<Edge> E;
vector<vector<int>> g;
vector<int> d, pt;
Dinic(int N) : N(N), E(0), g(N), d(N), pt(N) {}
void AddEdge(int u, int v, long long cap) {
if (u != v) {
E.push_back(Edge(u, v, cap));
g[u].push_back(E.size() - 1);
E.push_back(Edge(v, u, 0));
g[v].push_back(E.size() - 1);
}
}
bool BFS(int S, int T) {
queue<int> q({S});
fill(d.begin(), d.end(), N + 1);
d[S] = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
if (u == T) break;
for (int k : g[u]) {
Edge &e = E[k];
if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {
d[e.v] = d[e.u] + 1;
q.push(e.v);
}
}
}
return d[T] != N + 1;
}
long long DFS(int u, int T, long long flow = -1) {
if (u == T || flow == 0) return flow;
for (int &i = pt[u]; i < g[u].size(); ++i) {
Edge &e = E[g[u][i]];
Edge &oe = E[g[u][i] ^ 1];
if (d[e.v] == d[e.u] + 1) {
long long amt = e.cap - e.flow;
if (flow != -1 && amt > flow) amt = flow;
if (long long pushed = DFS(e.v, T, amt)) {
e.flow += pushed;
oe.flow -= pushed;
return pushed;
}
}
}
return 0;
}
long long MaxFlow(int S, int T) {
long long total = 0;
while (BFS(S, T)) {
fill(pt.begin(), pt.end(), 0);
while (long long flow = DFS(S, T)) total += flow;
}
return total;
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
vector<int> vec(6);
for (int i = 0; i < (long long)(6); i++) cin >> vec[i];
int n;
cin >> n;
int src = n + 7, snk = src + 1;
Dinic flow(snk + 1);
vector<string> hoba;
hoba.push_back("S");
hoba.push_back("M");
hoba.push_back("L");
hoba.push_back("XL");
hoba.push_back("XXL");
hoba.push_back("XXXL");
for (int i = 0; i < (long long)(6); i++) flow.AddEdge(i + n, snk, vec[i]);
for (int i = 0; i < (long long)(n); i++) {
string x;
cin >> x;
string a = "", b = "";
if (x.find(',') == string::npos)
a = x;
else {
int idx = x.find(',');
a = x.substr(0, idx);
b = x.substr(idx + 1, ((int)((x).size())) - idx);
}
for (int j = 0; j < (long long)(6); j++) {
if (a == hoba[j] || b == hoba[j]) flow.AddEdge(i, j + n, 1);
}
flow.AddEdge(src, i, 1);
}
if (flow.MaxFlow(src, snk) != n) return cout << "NO", 0;
cout << "YES\n";
for (int i = 0; i < (long long)(n); i++) {
for (auto j : flow.g[i]) {
auto x = flow.E[j];
if (x.flow == 1) {
cout << hoba[x.v - n] << '\n';
break;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100030;
const long long MODD = 1000000009;
int A[6];
int ans[MAX_N];
vector<int> v[MAX_N];
string s[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
void do_case() {
for (int i = 0; i < 6; i++) cin >> A[i];
int n;
cin >> n;
for (int i = 0; i < n; i++) ans[i] = -1;
for (int i = 0; i < n; i++) {
string t;
cin >> t;
if (t.find(',') == string::npos) {
int size = find(s, s + 6, t) - s;
A[size]--;
ans[i] = size;
if (A[size] < 0) {
cout << "NO" << endl;
return;
}
} else {
for (int ii = 0; ii < 2; ii++) {
string p = t.substr(0, t.find(','));
v[i].push_back(find(s, s + 6, p) - s);
t = t.substr(t.find(',') + 1);
}
if (v[i][0] > v[i][1]) swap(v[i][0], v[i][1]);
}
}
for (int k = 0; k < 3; k++) {
for (int i = 0; i < n; i++) {
if (ans[i] != -1) continue;
for (int z = 0; z < 2; z++) {
if (v[i][z] == k) {
if (A[k] == 0 && A[v[i][1 - z]] == 0) {
cout << "NO" << endl;
return;
}
ans[i] = (A[k] ? k : v[i][1 - z]);
A[ans[i]]--;
break;
}
if (v[i][z] == 5 - k) {
if (A[5 - k] == 0 && A[v[i][1 - z]] == 0) {
cout << "NO" << endl;
return;
}
ans[i] = (A[5 - k] ? 5 - k : v[i][1 - z]);
A[ans[i]]--;
break;
}
}
}
}
for (int i = 0; i < n; i++)
if (ans[i] == -1) {
cout << "NO" << endl;
return;
}
cout << "YES" << endl;
for (int i = 0; i < n; i++) cout << s[ans[i]] << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
do_case();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[6];
for (int i = 0; i < 6; i++) cin >> a[i];
int n;
cin >> n;
string ls[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
vector<int> type1(n), type2(n, -1);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
int pos = s.find(',');
if (pos == string::npos) {
type1[i] = find(ls, ls + 6, s) - ls;
} else {
type1[i] = find(ls, ls + 6, s.substr(0, pos)) - ls;
type2[i] = type1[i] + 1;
}
}
vector<int> t(n, -1);
for (int i = 0; i < 6; i++) {
for (int j = 0; j < n && a[i] > 0; j++) {
if (type1[j] == i && type2[j] == -1) {
t[j] = i;
type1[j] = -1;
a[i]--;
}
}
for (int j = 0; j < n; j++) {
if (type1[j] == i) {
if (a[i] > 0) {
t[j] = i;
type1[j] = -1;
type2[j] = -1;
a[i]--;
} else {
type1[j] = type2[j];
type2[j] = -1;
}
}
}
}
bool ok = true;
for (int i = 0; i < n; i++) ok &= t[i] != -1;
if (!ok) {
puts("NO");
return 0;
}
puts("YES");
for (int i = 0; i < n; i++) {
cout << ls[t[i]] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T, class S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
return os << "(" << v.first << ", " << v.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "[";
for (int i = int(0); i <= int((static_cast<int>((v).size())) - 1); ++i) {
if (i) os << ", ";
os << v[i];
}
return os << "]";
}
template <class T>
bool setmax(T& _a, T _b) {
if (_b > _a) {
_a = _b;
return true;
}
return false;
}
template <class T>
bool setmin(T& _a, T _b) {
if (_b < _a) {
_a = _b;
return true;
}
return false;
}
template <class T>
T gcd(T _a, T _b) {
return _b == 0 ? _a : gcd(_b, _a % _b);
}
const vector<string> sizes{"S", "M", "L", "XL", "XXL", "XXXL"};
int main() {
vector<int> tot(static_cast<int>((sizes).size()));
for (int& x : tot) scanf("%d", &x);
int n;
scanf("%d", &n);
vector<int> want(n);
vector<bool> loose(n);
for (int i = int(0); i <= int((n)-1); ++i) {
string s;
cin >> s;
loose[i] = false;
if (s.find(',') != string::npos) {
loose[i] = true;
s = s.substr(0, s.find(','));
}
want[i] = int(find((sizes).begin(), (sizes).end(), s) - sizes.begin());
}
for (int i = int(0); i <= int((n)-1); ++i)
if (!loose[i]) --tot[want[i]];
vector<pair<int, int> > p;
for (int i = int(0); i <= int((n)-1); ++i)
if (loose[i]) p.push_back(make_pair(want[i], i));
sort((p).begin(), (p).end());
for (pair<int, int> t : p) {
int i = t.second;
if (tot[want[i]] <= 0) ++want[i];
--tot[want[i]];
}
bool ok = true;
for (int i : tot)
if (i < 0) ok = false;
if (ok) {
printf("YES\n");
for (int i = int(0); i <= int((n)-1); ++i)
printf("%s\n", sizes[want[i]].c_str());
} else {
printf("NO\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
while (TESTS--) {
string a[] = {"S", "M", "L", "XL", "XXL", "XXXL"};
map<string, int> ct;
vector<pair<string, string> > b;
for (long long int i = 0; i < 6; i++) cin >> ct[a[i]];
int n;
cin >> n;
vector<string> ans(n);
fill((ans).begin(), (ans).end(), "null");
for (long long int i = 0; i < n; i++) {
string s, s1, s2;
cin >> s;
int k = 0;
while (s[k] != ',' && k < (long long int)s.size()) {
s1.push_back(s[k]);
k++;
}
if (s[k] != ',') {
ans[i] = s1;
ct[s1]--;
if (ct[s1] < 0) {
cout << "NO";
return 0;
}
b.push_back({s1, "Vf"});
continue;
}
k++;
while (k < (long long int)s.size()) {
s2.push_back(s[k]);
k++;
}
b.push_back({s1, s2});
}
for (long long int i = 0; i < 6; i++) {
for (long long int j = 0; j < n; j++) {
if (b[j].second == a[i]) {
if (ct[a[i]] > 0 && ans[j] == "null") {
ans[j] = a[i];
ct[a[i]]--;
}
}
}
for (long long int j = 0; j < n; j++) {
if (b[j].first == a[i]) {
if (ct[a[i]] > 0 && ans[j] == "null") {
ans[j] = a[i];
ct[a[i]]--;
}
}
}
}
for (long long int i = 0; i < n; i++) {
if (ans[i] == "null") {
cout << "NO";
return 0;
}
}
cout << "YES\n";
for (long long int i = 0; i < n; i++) cout << ans[i] << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const string LN = "\n";
const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = (int)2e9 + 7;
const long long LINF = (long long)9e18 + 7;
const long long P = 353251;
const long long P1 = 239017;
const long long P2 = 239017;
const long long MOD = 1e9 + 7;
const long long MOD2 = 1e9 + 9;
int a[7], n;
vector<int> q[6];
int ans[100007];
int get(string s) {
if (s == "S") return 0;
if (s == "M") return 1;
if (s == "L") return 2;
if (s == "XL") return 3;
if (s == "XXL") return 4;
if (s == "XXXL") return 5;
}
void print(int k) {
if (k == 0) cout << "S" << LN;
if (k == 1) cout << "M" << LN;
if (k == 2) cout << "L" << LN;
if (k == 3) cout << "XL" << LN;
if (k == 4) cout << "XXL" << LN;
if (k == 5) cout << "XXXL" << LN;
}
const bool is_testing = 0;
int main() {
srand('D' + 'E' + 'N' + 'I' + 'S' + 'S' + 'O' + 'N');
if (is_testing) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
} else {
}
for (int i = 0; i < 6; i++) cin >> a[i];
cin >> n;
for (int i = 0; i < n; i++) {
string now;
cin >> now;
string kek;
for (int i = 0; i < now.size(); i++) {
if (now[i] == ',') break;
kek += now[i];
}
int ha = get(kek);
if (now.size() == kek.size()) {
a[ha]--;
ans[i] = ha;
} else {
q[ha].push_back(i);
}
}
for (int i = 4; i >= 0; i--) {
for (int c : q[i]) {
if (a[i + 1] <= 0) {
ans[c] = i;
a[i]--;
} else {
ans[c] = i + 1;
a[i + 1]--;
}
}
}
for (int i = 0; i < 6; i++)
if (a[i] < 0) {
cout << "NO";
exit(0);
}
cout << "YES" << LN;
for (int i = 0; i < n; i++) print(ans[i]);
}
|
#include <bits/stdc++.h>
using namespace std;
const long long one = 1;
const long long INF = 2e18;
const long long MOD = 1e9 + 7;
const long long N = 40040 + 10;
const long long nul = 0;
signed main() {
vector<long long> cnt(6);
for (long long &i : cnt) cin >> i;
vector<pair<pair<long long, long long>, long long> > smth;
long long n;
cin >> n;
map<string, long long> dict;
dict["S"] = 0;
dict["M"] = 1;
dict["L"] = 2;
dict["XL"] = 3;
dict["XXL"] = 4;
dict["XXXL"] = 5;
bool can = 0;
vector<string> sz = {"S", "M", "L", "XL", "XXL", "XXXL"};
vector<string> ans(n);
for (long long i = 0; i < n; i++) {
string s;
cin >> s;
string now = "";
pair<long long, long long> q;
bool flag = 0;
for (char i : s) {
if (i == ',') {
q.first = dict[now];
now = "";
flag = 1;
} else {
now += i;
}
}
if (flag) {
q.second = dict[now];
if (q.second < q.first) {
swap(q.first, q.second);
}
smth.push_back({q, i});
} else {
if (cnt[dict[now]] == 0) {
can = 1;
} else {
cnt[dict[now]]--;
ans[i] = now;
}
}
}
if (can)
cout << "NO\n";
else {
sort((smth).begin(), (smth).end());
for (auto i : smth) {
long long one = i.first.first, two = i.first.second;
if (cnt[one] == 0) {
if (cnt[two] == 0) {
can = 1;
break;
} else {
ans[i.second] = sz[two];
cnt[two]--;
}
} else {
ans[i.second] = sz[one];
cnt[one]--;
}
}
if (can)
cout << "NO\n";
else {
cout << "YES\n";
for (auto i : ans) cout << i << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T mod_v(T num) {
if (num >= 0)
return num % 1000000007;
else
return (num % 1000000007 + 1000000007) % 1000000007;
}
template <class T>
inline T gcd(T a, T b) {
a = abs(a);
b = abs(b);
while (b) b ^= a ^= b ^= a %= b;
return a;
}
template <class T>
T fast_pow(T n, T p) {
if (p == 0) return 1;
if (p % 2) {
T g = mod_v(mod_v(n) * mod_v(fast_pow(n, p - 1)));
return g;
} else {
T g = fast_pow(n, p / 2);
g = mod_v(mod_v(g) * mod_v(g));
return g;
}
}
template <class T>
inline T modInverse(T n) {
return fast_pow(n, 1000000007 - 2);
}
bool equalTo(double a, double b) {
if (fabs(a - b) <= 1e-9)
return true;
else
return false;
}
bool notEqual(double a, double b) {
if (fabs(a - b) > 1e-9)
return true;
else
return false;
}
bool lessThan(double a, double b) {
if (a + 1e-9 < b)
return true;
else
return false;
}
bool lessThanEqual(double a, double b) {
if (a < b + 1e-9)
return true;
else
return false;
}
bool greaterThan(double a, double b) {
if (a > b + 1e-9)
return true;
else
return false;
}
bool greaterThanEqual(double a, double b) {
if (a + 1e-9 > b)
return true;
else
return false;
}
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
int nextInt() {
int n;
scanf("%d", &n);
return n;
}
long long nextLong() {
long long n;
scanf("%lld", &n);
return n;
}
void print(int n) { printf("%d", n); }
void println(int n) { printf("%d\n", n); }
void println(long long n) { printf("%lld\n", n); }
template <class T>
inline int in(register T& num) {
register char c = 0;
num = 0;
bool n = false;
while (c < 33) c = getchar();
while (c > 33) {
if (c == '-')
n = true;
else
num = num * 10 + c - '0';
c = getchar();
}
num = n ? -num : num;
return 1;
}
string tshirt[] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int cnt[10];
string res[1000004];
int main() {
int var;
int n;
map<string, int> val;
for (int i = 0; i < 6; i++) {
in(var);
val[tshirt[i]] = i;
cnt[i] = var;
}
in(n);
bool ok = true;
vector<pair<int, pair<int, int> > > pos;
for (int i = 1; i <= n; i++) {
char s[10];
char* tmp;
char v[] = ",";
scanf("%s", s);
if (!ok) continue;
tmp = strtok(s, v);
int l = 100, r = -1;
while (tmp != NULL) {
l = min(l, val[tmp]);
r = max(r, val[tmp]);
tmp = strtok(NULL, v);
}
if (l == r) {
if (cnt[l] == 0)
ok = false;
else {
cnt[l]--;
res[i] = tshirt[l];
}
} else
pos.push_back({l, {r, i}});
}
sort((pos).begin(), (pos).end());
for (auto i : pos) {
if (!ok) break;
if (cnt[i.first]) {
cnt[i.first]--;
res[i.second.second] = tshirt[i.first];
} else if (cnt[i.second.first]) {
cnt[i.second.first]--;
res[i.second.second] = tshirt[i.second.first];
} else
ok = false;
}
if (!ok)
printf("NO\n");
else {
printf("YES\n");
for (int i = 1; i <= n; i++) cout << res[i] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
string choice[N];
int s, m, l, xl, xxl, xxxl;
map<string, int> cnt;
vector<string> chp[N];
string answer[N];
string tp[] = {"S", "M", "L", "XL", "XXL", "XXXL"};
int main() {
scanf("%d%d%d%d%d%d", &s, &m, &l, &xl, &xxl, &xxxl);
cnt["S"] = s;
cnt["M"] = m;
cnt["L"] = l;
cnt["XL"] = xl;
cnt["XXL"] = xxl;
cnt["XXXL"] = xxxl;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> choice[i];
size_t found = choice[i].find(',');
if (found == string::npos) {
chp[i].push_back(choice[i]);
} else {
string a = choice[i].substr(0, found);
string b = choice[i].substr(found + 1, string::npos);
chp[i].push_back(a);
chp[i].push_back(b);
}
}
for (string yo : tp) {
for (int i = 0; i < n; i++) {
if (chp[i].size() == 1 && chp[i][0].compare(yo) == 0) {
if (cnt[yo]) {
answer[i] = yo;
cnt[yo]--;
chp[i].clear();
} else {
printf("NO\n");
return 0;
}
}
}
for (int i = 0; i < n; i++) {
if (chp[i].size() == 2 && chp[i][0].compare(yo) == 0) {
if (cnt[yo]) {
answer[i] = yo;
cnt[yo]--;
chp[i].clear();
} else {
swap(chp[i][0], chp[i][1]);
chp[i].pop_back();
}
}
}
}
printf("YES\n");
for (int i = 0; i < n; i++) cout << answer[i] << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
cin.tie(NULL);
const int NSIZE = 6;
const char *sizes[] = {"S", "M", "L", "XL", "XXL", "XXXL"};
vector<int> g(NSIZE);
for (int i = 0; i < NSIZE; i++) cin >> g[i];
int n;
cin >> n;
vector<int> r(n);
vector<vector<int>> h(NSIZE - 1);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s == "S") {
if (--g[0] < 0) goto failed;
r[i] = 0;
} else if (s == "M") {
if (--g[1] < 0) goto failed;
r[i] = 1;
} else if (s == "L") {
if (--g[2] < 0) goto failed;
r[i] = 2;
} else if (s == "XL") {
if (--g[3] < 0) goto failed;
r[i] = 3;
} else if (s == "XXL") {
if (--g[4] < 0) goto failed;
r[i] = 4;
} else if (s == "XXXL") {
if (--g[5] < 0) goto failed;
r[i] = 5;
} else if (s == "S,M") {
h[0].push_back(i);
} else if (s == "M,L") {
h[1].push_back(i);
} else if (s == "L,XL") {
h[2].push_back(i);
} else if (s == "XL,XXL") {
h[3].push_back(i);
} else if (s == "XXL,XXXL") {
h[4].push_back(i);
}
}
for (int i = 0; i < 5; i++) {
while (!h[i].empty()) {
if (g[i] > 0) {
g[i]--;
r[h[i].back()] = i;
h[i].pop_back();
} else if (g[i + 1] > 0) {
g[i + 1]--;
r[h[i].back()] = i + 1;
h[i].pop_back();
} else {
goto failed;
}
}
}
cout << "YES" << endl;
for (auto c : r) cout << sizes[c] << endl;
return 0;
failed:
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const double PI = 2 * acos(0.0);
inline int cmp(double x, double y = 0, double tol = EPS) {
return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
bool debug = false;
int main(void) {
vector<int> vet(6);
for (int i = 0; i < 6; ++i) {
cin >> vet[i];
}
int n;
scanf("%d", &n);
vector<pair<int, int> > par(n);
vector<int> aux(20);
for (int i = 0; i < n; ++i) {
char c[20];
scanf("%s", c);
int p;
if (c[0] == 'S') {
par[i].first = 0;
p = 1;
} else if (c[0] == 'M') {
par[i].first = 1;
p = 1;
} else if (c[0] == 'L') {
par[i].first = 2;
p = 1;
} else if (c[1] == 'L') {
par[i].first = 3;
p = 2;
} else if (c[2] == 'L') {
par[i].first = 4;
p = 3;
} else {
par[i].first = 5;
p = 4;
}
if (c[p] != ',') {
par[i].second = par[i].first;
aux[par[i].first]++;
} else {
par[i].second = par[i].first + 1;
aux[7 + par[i].first]++;
}
}
bool possivel = true;
vector<int> sob(6);
vector<int> sob2(6);
for (int i = 0; i < 6; ++i) {
if (vet[i] < aux[i]) {
possivel = false;
}
sob[i] = vet[i] - aux[i];
sob2[i] = vet[i] - aux[i];
}
for (int i = 0; i < 6; ++i) {
if (sob[i] < aux[6 + i]) {
possivel = false;
}
sob[i] -= aux[6 + i];
if (sob[i] > 0) {
aux[7 + i] -= min(sob[i], aux[7 + i]);
}
}
string sai[6];
sai[0] = "S";
sai[1] = "M";
sai[2] = "L";
sai[3] = "XL";
sai[4] = "XXL";
sai[5] = "XXXL";
string ss[n];
if (possivel) {
cout << "YES" << endl;
for (int i = 0; i < 6; ++i) {
if (debug) {
cout << "vet[i] << \" \" << sob[i] << \" \" << aux[i]"
<< " is " << vet[i] << " " << sob[i] << " " << aux[i] << endl;
};
}
for (int i = 0; i < n; ++i) {
if (par[i].first == par[i].second) {
ss[i] = sai[par[i].first];
}
}
for (int j = 0; j < 6; ++j) {
for (int i = 0; i < n; ++i) {
if (par[i].first != par[i].second && par[i].first == j) {
if (sob2[par[i].first] > 0) {
ss[i] = sai[par[i].first];
--sob2[par[i].first];
} else {
ss[i] = sai[par[i].second];
--sob2[par[i].second];
}
}
}
}
for (int i = 0; i < n; ++i) {
cout << ss[i] << endl;
}
} else {
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int check(string s) {
if (s == "S") return 0;
if (s == "M") return 1;
if (s == "L") return 2;
if (s == "XL") return 3;
if (s == "XXL") return 4;
if (s == "XXXL") return 5;
}
int main() {
ios::sync_with_stdio(false);
int arr[6], i;
for (i = 0; i <= 5; i++) {
cin >> arr[i];
}
int n;
cin >> n;
vector<pair<int, pair<int, int> > > v;
for (i = 0; i <= n - 1; i++) {
string temp;
cin >> temp;
int j = 0;
string s1, s2;
while (j < temp.length() && temp[j] != ',') {
s1 += temp[j++];
}
j++;
while (j < temp.length()) {
s2 += temp[j++];
}
if (s2.length() > 0)
v.push_back(make_pair(check(s1), make_pair(check(s2), i)));
else
v.push_back(make_pair(check(s1), make_pair(-1e9, i)));
}
sort(v.begin(), v.end());
int dp[n];
for (i = 0; i <= n - 1; i++) {
if (v[i].second.first == -1e9) {
if (arr[v[i].first]) {
arr[v[i].first]--;
dp[v[i].second.second] = v[i].first;
} else {
cout << "NO\n";
return 0;
}
} else {
if (arr[v[i].first]) {
arr[v[i].first]--;
dp[v[i].second.second] = v[i].first;
} else if (arr[v[i].second.first]) {
arr[v[i].second.first]--;
dp[v[i].second.second] = v[i].second.first;
} else {
cout << "NO\n";
return 0;
}
}
}
cout << "YES\n";
for (i = 0; i <= n - 1; i++) {
if (dp[i] == 0) cout << "S\n";
if (dp[i] == 1) cout << "M\n";
if (dp[i] == 2) cout << "L\n";
if (dp[i] == 3) cout << "XL\n";
if (dp[i] == 4) cout << "XXL\n";
if (dp[i] == 5) cout << "XXXL\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int c[21], b[21], a[21], s[21];
string x[100005];
int main() {
int n;
for (int i = 0; i <= 10; i = i + 2) scanf("%d", &c[i]);
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> x[i];
if (x[i] == "S")
a[0]++;
else if (x[i] == "S,M")
a[1]++;
else if (x[i] == "M")
a[2]++;
else if (x[i] == "M,L")
a[3]++;
else if (x[i] == "L")
a[4]++;
else if (x[i] == "L,XL")
a[5]++;
else if (x[i] == "XL")
a[6]++;
else if (x[i] == "XL,XXL")
a[7]++;
else if (x[i] == "XXL")
a[8]++;
else if (x[i] == "XXL,XXXL")
a[9]++;
else
a[10]++;
}
int checker = 1;
for (int i = 0; i <= 10; i++) {
b[i] = a[i];
}
for (int i = 0; i <= 10; i++) {
if (i % 2 == 0) {
c[i] -= a[i];
if (c[i] < 0) checker = 0;
} else {
a[i] -= c[i - 1];
s[i] += c[i - 1];
if (a[i] > 0) c[i + 1] -= a[i];
}
}
if (checker == 0) {
printf("NO");
return 0;
}
printf("YES\n");
for (int i = 0; i < n; i++) {
if (x[i] == "S")
printf("S\n");
else if (x[i] == "S,M") {
if (s[1] > 0) {
printf("S\n");
s[1]--;
} else
printf("M\n");
} else if (x[i] == "M")
printf("M\n");
else if (x[i] == "M,L") {
if (s[3] > 0) {
printf("M\n");
s[3]--;
} else
printf("L\n");
} else if (x[i] == "L")
printf("L\n");
else if (x[i] == "L,XL") {
if (s[5] > 0) {
printf("L\n");
s[5]--;
} else
printf("XL\n");
} else if (x[i] == "XL")
printf("XL\n");
else if (x[i] == "XL,XXL") {
if (s[7] > 0) {
printf("XL\n");
s[7]--;
} else
printf("XXL\n");
} else if (x[i] == "XXL")
printf("XXL\n");
else if (x[i] == "XXL,XXXL") {
if (s[9] > 0) {
printf("XXL\n");
s[9]--;
} else
printf("XXXL\n");
} else
printf("XXXL\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
string sizes[6] = {"S", "M", "L", "XL", "XXL", "XXXL"};
map<string, int> nums;
vector<int> cnt(6);
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < 6; i++) {
nums[sizes[i]] = i;
cin >> cnt[i];
}
int n;
cin >> n;
vector<set<pair<int, int> > > needs(6);
vector<string> ans(n, "-");
for (int i = 0; i < n; i++) {
string s;
cin >> s;
int sl = -1;
for (int j = 0; j < (int)s.size(); j++) {
if (s[j] == ',') {
sl = j;
break;
}
}
if (sl == -1) {
ans[i] = s;
cnt[nums[s]]--;
if (cnt[nums[s]] < 0) {
cout << "NO\n";
return 0;
}
} else {
needs[nums[s.substr(0, sl)]].insert({1, i});
needs[nums[s.substr(sl + 1, (int)s.size() - sl - 1)]].insert({0, i});
}
}
for (int i = 0; i < 6; i++) {
while (cnt[i] > 0 && !needs[i].empty()) {
if (ans[needs[i].begin()->second] == "-") {
ans[needs[i].begin()->second] = sizes[i];
cnt[i]--;
}
needs[i].erase(needs[i].begin());
}
}
for (int i = 0; i < 6; i++) {
if (cnt[i] < 0) {
cout << "NO\n";
return 0;
}
}
for (int i = 0; i < n; i++) {
if (ans[i] == "-") {
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
for (auto t : ans) {
cout << t << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<string, long long> ma;
long long a[100010][10], b[100], us[1000000];
string tr[100];
pair<long long, pair<long long, long long> > c[1000000];
int main() {
long long n, i, j;
ma["S"] = 1;
ma["M"] = 2;
ma["L"] = 3;
ma["XL"] = 4;
ma["XXL"] = 5;
ma["XXXL"] = 6;
tr[1] = "S";
tr[2] = "M";
tr[3] = "L";
tr[4] = "XL";
tr[5] = "XXL";
tr[6] = "XXXL";
long long kol = 0;
for (i = 1; i <= 6; i++) cin >> b[i];
cin >> n;
string str = "", s;
for (i = 1; i <= n; i++) {
cin >> s;
long long k = 0;
str = "";
for (j = 0; j < s.size(); j++) {
if (s[j] == ',') {
k++, a[i][k] = ma[str];
str = "";
} else
str = str + s[j];
}
k++, a[i][k] = ma[str];
if (k == 2) {
kol++;
c[kol].first = a[i][1];
c[kol].second.first = a[i][2];
c[kol].second.second = i;
} else {
us[i] = a[i][1];
b[a[i][1]]--;
if (b[a[i][1]] == -1) {
cout << "NO";
return 0;
}
}
}
sort(c + 1, c + 1 + kol);
for (i = 1; i <= kol; i++) {
if (b[c[i].first] != 0) {
us[c[i].second.second] = c[i].first;
b[c[i].first]--;
} else {
if (b[c[i].second.first] != 0)
us[c[i].second.second] = c[i].second.first;
else {
cout << "NO";
return 0;
}
b[c[i].second.first]--;
}
}
cout << "YES\n";
for (i = 1; i <= n; i++) {
cout << tr[us[i]] << '\n';
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.