We want to mention BamiTorabi and Amoo_Safar who we thank for helping us with translating the problems and writing the tutorials.and we want to apologize for div1 A2 and B hopefully you will forgive us :( .
Tutorial is loading...
Prepared by Mohammad.H915
official solution
// In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define ll long long
#define ld long double
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 3e5 + 100, OO = 1e9 + 7, T = 50, M = 1e9 + 7, P = 6151, SQ = 280, lg = 20;
typedef pair <int, int> pii;
void solve() {
int n, c0, c1, t;
string s;
cin >> n >> c0 >> c1 >> t >> s;
int ans = 0;
for(auto u : s) {
if(u == '0')
ans += min(c0, c1 + t);
else
ans += min(c1, c0 + t);
}
cout << ans << endl;
}
int32_t main() {
int t;
cin >> t;
while(t--)
solve();
return 0;
}
Tutorial is loading...
official solution
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
ll a[N];
int Main(){
ll n, k;
cin >> k >> n;
for (int i=1;i<=n*k;i++){
cin >> a[i];
}
ll x=(k+1)/2 - 1;
x = k - x;
ll z=n*k+1;
ll ans=0;
while(n--){
z-=x;
if (z<=0) break;
ans+=a[z];
}
cout << ans << endl;
}
int32_t main(){
ll t;
cin >> t;
while(t--){
Main();
}
}
Prepared by Mohammad.H915
Tutorial is loading...
official solution
// In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define ll long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 200, OO = 1e9 + 7, T = 50, M = 1e9 + 7, P = 6151, SQ = 280, lg = 20;
typedef pair <int, int> pii;
char c[N][N];
bool cnt[N][N];
struct node {int x1, y1, x2, y2, x3, y3;} p[5];
vector <node> v;
void upd(int x, int y, int tp, bool is) {
if(is)
v.pb({x + p[tp].x1, y + p[tp].y1, x + p[tp].x2, y + p[tp].y2, x + p[tp].x3, y + p[tp].y3});
else
cnt[x + p[tp].x1][y + p[tp].y1] ^= 1, cnt[x + p[tp].x2][y + p[tp].y2] ^= 1, cnt[x + p[tp].x3][y + p[tp].y3] ^= 1;
}
void solve() {
int n, m, od = 0;
v.clear();
cin >> n >> m;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cin >> c[i][j];
if(c[i][j] == '1')
od++, cnt[i][j] = true;
else
cnt[i][j] = false;
}
}
if(od == 0) {
cout << 0 << endl;
return;
}
if(n == 1 || m == 1) {
cout << -1 << endl;
return;
}
for(int i = 1; i <= n - 2; i++) {
for(int j = 1; j <= m; j++) {
if(cnt[i][j]) {
if(j != m) {
v.pb({i, j, i + 1, j, i + 1, j + 1});
cnt[i][j] ^= 1, cnt[i + 1][j] ^= 1, cnt[i + 1][j + 1] ^= 1;
}
else {
v.pb({i, j, i + 1, j, i + 1, j - 1});
cnt[i][j] ^= 1, cnt[i + 1][j] ^= 1, cnt[i + 1][j - 1] ^= 1;
}
}
}
}
for(int i = 1; i <= m - 2; i++) {
if(cnt[n - 1][i]) {
v.pb({n - 1, i, n - 1, i + 1, n, i + 1});
cnt[n - 1][i] ^= 1, cnt[n - 1][i + 1] ^= 1, cnt[n][i + 1] ^= 1;
}
if(cnt[n][i]) {
v.pb({n, i, n - 1, i + 1, n, i + 1});
cnt[n][i] ^= 1, cnt[n - 1][i + 1] ^= 1, cnt[n][i + 1] ^= 1;
}
}
for(int msk = 0; msk < (1 << 4); msk++) {
for(int j = 0; j < 4; j++)
if(msk & (1 << j))
upd(n - 1, m - 1, j, 0);
if(!cnt[n - 1][m - 1] && !cnt[n - 1][m] && !cnt[n][m - 1] && !cnt[n][m]) {
for(int j = 0; j < 4; j++)
if(msk & (1 << j))
upd(n - 1, m - 1, j, 1);
break;
}
for(int j = 0; j < 4; j++)
if(msk & (1 << j))
upd(n - 1, m - 1, j, 0);
}
cout << (int)v.size() << endl;
for(auto u : v)
cout << u.x1 << " " << u.y1 << " " << u.x2 << " " << u.y2 << " " << u.x3 << " " << u.y3 << endl;
}
int32_t main(){
use_fast;
p[0] = {0, 0, 0, 1, 1, 0}, p[1] = {0, 1, 0, 0, 1, 1}, p[2] = {1, 0, 1, 1, 0, 0}, p[3] = {1, 1, 0, 1, 1, 0};
int t;
cin >> t;
while(t--)
solve();
return 0;
}
Prepared by Mohammad.H915
Tutorial is loading...
official solution
// In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
//#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 1e5 + 100, OO = 1e9 + 7, T = 22, M = 1e9 + 7, P = 6151, SQ = 1300, lg = 22;
typedef pair <int, int> pii;
int mark[N], deg[N], ct[N];
bool ans[N], can[N];
vector <int> v[N], A;
vector <pii> ch[N];
bool cmp(int x, int y) {
return mark[x] < mark[y];
}
void solve() {
int n, m, k;
cin >> n >> m >> k;
A.clear();
for(int i = 0; i <= n; i++)
v[i].clear(), ch[i].clear(), mark[i] = deg[i] = ct[i] = 0, ans[i] = can[i] = false;
for(int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
v[x].pb(y);
v[y].pb(x);
}
if(k > 500) {
cout << -1 << endl;
return;
}
set <pii> st;
for(int i = 1; i <= n; i++)
st.insert({deg[i] = (int)v[i].size(), i});
int cnt = 1;
while((int)st.size()) {
pii p = *st.begin();
if(p.ff >= k) {
cout << 1 << " " << (int)st.size() << endl;
for(auto u : st)
cout << u.ss << " ";
cout << endl;
return;
}
else {
st.erase(p);
mark[p.ss] = cnt;
for(auto u : v[p.ss])
if(!mark[u])
st.erase({deg[u], u}), st.insert({--deg[u], u});
A.pb(p.ss);
}
cnt++;
}
for(auto i : A) {
int nxt = 0;
for(auto u : v[i])
if(mark[u] > mark[i])
ct[nxt++] = u, can[u] = true;
for(auto u : ch[i])
if(!can[u.ff])
ans[u.ss] = false;
for(int j = 0; j < nxt; j++)
can[ct[j]] = false;
if(nxt != k - 1)
continue;
ans[i] = true;
sort(ct, ct + nxt, cmp);
for(int j = 0; j < nxt; j++)
for(int k = j + 1; k < nxt; k++)
ch[ct[j]].pb({ct[k], i});
}
for(auto i : A) {
if(!ans[i])
continue;
cout << 2 << endl;
cout << i << " ";
for(auto u : v[i])
if(mark[u] > mark[i])
cout << u << " ";
cout << endl;
return;
}
cout << -1 << endl;
return;
}
int32_t main() {
use_fast;
int t;
cin >> t;
while(t--)
solve();
return 0;
}
Prepared by AliShahali1382
Tutorial is loading...
prepared by Mehrdad_Sohrabi
Tutorial is loading...
prepared by Mehrdad_Sohrabi
Tutorial is loading...
will be ready soon.
Prepared by AliShahali1382