Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions 01GAME_1373B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frn(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define test int t;cin>>t; while(t--)
#define mp make_pair
#define pb push_back
#define pu push
#define fi first
#define se second
#define mod 1000000007
void fast() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
bool myc(int a,int b) {
return a>b;
}

int32_t main() {
fast();
test{
string s;
cin>>s;
int n = s.length();
int ones = 0;
int zeros = 0;
fr(i,0,n) if(s[i] == '0') zeros++; else ones++;
int e = min(zeros,ones);
if(e%2 == 1) cout<<"DA"<<endl;
else cout<<"NET"<<endl;
}
return 0;
}
22 changes: 22 additions & 0 deletions 1342A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<bits/stdc++.h>
using namespace std;
#define int long long

int32_t main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t;cin>>t;
while(t--){
int x,y,a,b;
cin>>x>>y>>a>>b;
int ans = 0;
if(b<2*a){
int l = abs(x-y);
ans = min(x,y)*b + a*l;
}
else ans = (x+y)*a;
cout<<ans<<endl;
}
}
67 changes: 67 additions & 0 deletions 369NUMBERS_HB.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frn(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define test int t;cin>>t; while(t--)
#define mp make_pair
#define pb push_back
#define pu push
#define fi first
#define se second
#define mod 1000000007
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> seti;
void fast() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int l;
string a, b, s;
int dp[51][17][17][17];
int solve(int pos, int tr, int si, int ni, int t) {
if (tr == l || si == l || ni == l) return 0;
if (pos == s.length()) return (tr == si) & (si == ni) & (tr > 0);
if (dp[pos][tr][si][ni] != -1 && !t) return dp[pos][tr][si][ni];
int e = t ? s[pos] - '0' : 9;
int ret = 0;
fr(i, 0, e + 1) ret += solve(pos + 1, tr + (i == 3), si + (i == 6), ni + (i == 9), t & (i == e));
return t?ret:dp[pos][tr][si][ni] = ret % mod;
}
int32_t main () {
fast();
int t; cin >> t;
while (t--) {
cin >> a >> b;
//memset(dp, -1, sizeof dp);
int w3 = 0, w6 = 0, w9 = 0;
l = a.length()/3+1;
fr(i,0,a.length()) fr(j,0,l) fr(k,0,l) fr(e,0,l) dp[i][j][k][e] = -1;
fr(i, 0, a.length()) {
if (a[i] == '3') w3++;
else if (a[i] == '6') w6++;
else if (a[i] == '9') w9++;
}
s = a;
if (w3 > 0) w3 = (w3 == w6) & (w6 == w9);
int k = solve(0, 0, 0, 0, 1);
//memset(dp, -1, sizeof dp);

s = b;
l = b.length()/3+1;
fr(i,0,b.length()) fr(j,0,l) fr(k,0,l) fr(e,0,l)dp[i][j][k][e] = -1;
int d = solve(0, 0, 0, 0, 1);
cout << (d - k + w3+mod)%mod << endl;
}
return 0;
}
51 changes: 51 additions & 0 deletions 3n+1_Uva100.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
int dp[1000001] = {0};

int findVal(int k){
if(dp[k]) return dp[k];
if(k&1){
if(k>1000000){
return 2+findVal((3*k+1)>>1);
}
else{
int ans = 2+findVal((3*k+1)>>1);
dp[k] = ans;
return dp[k];
}
}
else{
if(k>1000000) return 1+findVal(k/2);
else{
int ans = 1+findVal(k/2);
dp[k] = ans;
return dp[k];
}
}
}

int32_t main(){
#ifndef ONLINE_JUDGE
freopen("input.txt" , "r",stdin);
freopen("output.txt","w",stdout);
#endif
dp[1] = 1;

int i,j;
int ans;
while(cin>>i&&cin>>j){
ans = 0;
if(i>j){
int temp = i;
i = j;
j = temp;
}
for(int h=i;h<=j;h++){
ans = max(ans,findVal(h));
}

cout<<i<<" "<<j<<" "<<ans<<endl;
}
return 0;
}
112 changes: 112 additions & 0 deletions 505_1391D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frn(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define test int t;cin>>t; while(t--)
#define mp make_pair
#define pb push_back
#define pu push
#define fi first
#define se second
#define mod 1000000007
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> seti;
void fast() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int n,m;
int a[1000005][3];
int b[3][1000005];
int32_t main () {
fast();
cin>>n>>m;
int k = min(n,m);
if(k>3){
int l = n*m;
fr(i,0,l) cin>>m;
cout<<"-1"<<endl;
}
else if(k==1){
int l = n*m;
fr(i,0,l) cin>>m;
cout<<"0";
}
else{
if(m>n){
char r;
fr(i,0,n) fr(j,0,m){
cin>>r;
b[i][j] = (r=='1');
}
//fr(i,0,n) {fr(j,0,m) cout<<b[i][j]; cout<<endl;}
fr(i,0,n) fr(j,0,m) a[j][i] = b[i][j];
swap(n,m);
}
else {
char r;
fr(i,0,n) fr(j,0,m) {
cin>>r;
a[i][j] = (r=='1'); }
}
// fr(i,0,n) {fr(j,0,m) cout<<a[i][j]; cout<<endl;}
if(m==2){
int dp[n+1][4];
dp[0][0] = (a[0][0]^0LL) + (a[0][1]^0LL);
dp[0][1] = (a[0][0]^1LL) + (a[0][1]^0LL);
dp[0][2] = (a[0][0]^0LL) + (a[0][1]^1LL);
dp[0][3] = (a[0][0]^1LL) + (a[0][1]^1LL);
fr(i,1,n){
fr(j,0,4){
if(j==0) dp[i][j] = min(dp[i-1][1],dp[i-1][2]) + (a[i][0]^0LL) + (a[i][1]^0LL);
else if(j==1) dp[i][j] = min(dp[i-1][0],dp[i-1][3]) + (a[i][0]^1LL) + (a[i][1]^0LL);
else if(j==2) dp[i][j] = min(dp[i-1][0],dp[i-1][3]) + (a[i][0]^0LL) + (a[i][1]^1LL);
else dp[i][j] = min(dp[i-1][1],dp[i-1][2]) + (a[i][0]^1LL) + (a[i][1]^1LL);
}
}
int ans = 1e9;
fr(i,0,4) ans = min(ans,dp[n-1][i]);
cout<<ans;
}
else{
int dp[n+1][8];
dp[0][0] = (a[0][0]^0LL) + (a[0][1]^0LL) + (a[0][2]^0LL);
dp[0][1] = (a[0][0]^1LL) + (a[0][1]^0LL) + (a[0][2]^0LL);
dp[0][2] = (a[0][0]^0LL) + (a[0][1]^1LL) + (a[0][2]^0LL);
dp[0][3] = (a[0][0]^1LL) + (a[0][1]^1LL) + (a[0][2]^0LL);
dp[0][4] = (a[0][0]^0LL) + (a[0][1]^0LL) + (a[0][2]^1LL);
dp[0][5] = (a[0][0]^1LL) + (a[0][1]^0LL) + (a[0][2]^1LL);
dp[0][6] = (a[0][0]^0LL) + (a[0][1]^1LL) + (a[0][2]^1LL);
dp[0][7] = (a[0][0]^1LL) + (a[0][1]^1LL) + (a[0][2]^1LL);

fr(i,1,n){
fr(j,0,8){
if(j==0) dp[i][j] = min(dp[i-1][5],dp[i-1][2]) + (a[i][0]^0LL) + (a[i][1]^0LL) + (a[i][2]^0LL);
else if(j==1) dp[i][j] = min(dp[i-1][4],dp[i-1][3]) + (a[i][0]^1LL) + (a[i][1]^0LL) + (a[i][2]^0LL);
else if(j==2) dp[i][j] = min(dp[i-1][0],dp[i-1][7]) + (a[i][0]^0LL) + (a[i][1]^1LL) + (a[i][2]^0LL);
else if(j==3) dp[i][j] = min(dp[i-1][6],dp[i-1][1]) + (a[i][0]^1LL) + (a[i][1]^1LL) + (a[i][2]^0LL);
else if(j==4) dp[i][j] = min(dp[i-1][6],dp[i-1][1]) + (a[i][0]^0LL) + (a[i][1]^0LL) + (a[i][2]^1LL);
else if(j==5) dp[i][j] = min(dp[i-1][0],dp[i-1][7]) + (a[i][0]^1LL) + (a[i][1]^0LL) + (a[i][2]^1LL);
else if(j==6) dp[i][j] = min(dp[i-1][3],dp[i-1][4]) + (a[i][0]^0LL) + (a[i][1]^1LL) + (a[i][2]^1LL);
else if(j==7) dp[i][j] = min(dp[i-1][5],dp[i-1][2]) + (a[i][0]^1LL) + (a[i][1]^1LL) + (a[i][2]^1LL);

}
// cout<<endl;
}
int ans = 1e9;
fr(i,0,8) ans = min(ans,dp[n-1][i]);
cout<<ans;
}
}
}
40 changes: 40 additions & 0 deletions A Cookie for You_1371C.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frn(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define test int t;cin>>t; while(t--)
#define mp make_pair
#define pb push_back
#define pu push
#define fi first
#define se second
#define mod 1000000007
void fast() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
bool myc(int a,int b) {
return a>b;
}
int32_t main() {
fast();
test{
int a,b,n,m;
cin>>a>>b>>n>>m;
if(a+b<n+m) cout<<"No"<<endl;
else{
int d = min(a,b);
if(d>=m) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
return 0;
}
Loading