Skip to content

Commit 41f734e

Browse files
committed
more problems solved
1 parent b8919d0 commit 41f734e

File tree

20 files changed

+1515
-0
lines changed

20 files changed

+1515
-0
lines changed

CodeChef/CROCDILE.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
5+
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
6+
7+
typedef long long ll;
8+
typedef long double ld;
9+
typedef pair<ll,ll> pii;
10+
11+
#define optimize ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define endl "\n"
13+
14+
#define fi first
15+
#define se second
16+
#define pb push_back
17+
18+
#define sz(x) (ll)(x.size())
19+
#define all(x) x.begin(),x.end()
20+
#define FOR(x,a,n) for(int x= (int)(a);(x) < int(n);(x)++)
21+
#define ms(x,a) memset(x,a,sizeof(x))
22+
23+
#define INF 0x3f3f3f3f
24+
#define INFLL 0x3f3f3f3f3f3f3f3f
25+
26+
#define mod 1000000007
27+
#define MAXN 200010
28+
29+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
30+
ll T,N,M,K;
31+
vector<vector<pii>> adj;
32+
vector<int> ex;
33+
34+
ll dijkstra(){
35+
36+
vector<pii> dist(N,pii(INFLL,INFLL));
37+
38+
bool v[N] = {0};
39+
set<pii> s;
40+
41+
FOR(i,0,sz(ex)){
42+
dist[ ex[i] ] = pii(0,0);
43+
s.insert(pii(0,ex[i]));
44+
}
45+
46+
while(!s.empty()){
47+
ll u = s.begin()->second;
48+
s.erase(s.begin());
49+
50+
v[u] = true;
51+
52+
if(dist[u].se == INFLL) break;
53+
54+
for(int i=0;i<adj[u].size();i++){
55+
ll w = adj[u][i].first;
56+
ll p = adj[u][i].second;
57+
58+
if(v[w]) continue;
59+
else{
60+
61+
if(dist[w].fi > dist[u].se + p ){
62+
63+
ll aux = dist[u].se + p;
64+
65+
s.erase(pii(dist[w].se , w));
66+
67+
dist[w].se = dist[w].fi;
68+
dist[w].fi = aux;
69+
70+
s.insert(pii(dist[w].se , w));
71+
72+
}else if(dist[w].se > dist[u].se + p ){
73+
74+
ll aux = dist[u].se + p;
75+
76+
s.erase(pii(dist[w].se , w));
77+
78+
dist[w].se = aux;
79+
80+
s.insert(pii(dist[w].se , w));
81+
}
82+
}
83+
}
84+
}
85+
86+
return dist[0].se;
87+
}
88+
89+
void solve(){
90+
cout << dijkstra() << endl;
91+
}
92+
93+
int main(){
94+
95+
optimize;
96+
cin >> N >> M >> K;
97+
98+
adj.resize(N);
99+
ex.resize(K);
100+
101+
FOR(i,0,M){
102+
ll a,b,c;
103+
cin >> a >> b >> c;
104+
105+
adj[a].pb(pii(b,c));
106+
adj[b].pb(pii(a,c));
107+
}
108+
109+
FOR(i,0,K) cin >> ex[i];
110+
111+
solve();
112+
113+
return 0;
114+
}

Codeforces/1141A.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
5+
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
6+
7+
typedef unsigned long long ll;
8+
typedef long double ld;
9+
typedef pair<int,int> pii;
10+
11+
#define optimize ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define endl "\n"
13+
14+
#define fi first
15+
#define se second
16+
#define pb push_back
17+
18+
#define sz(x) (ll)(x.size())
19+
#define all(x) x.begin(),x.end()
20+
#define FOR(x,a,n) for(int x= (int)(a);(x) < int(n);(x)++)
21+
#define ms(x,a) memset(x,a,sizeof(x))
22+
23+
#define INF 0x3f3f3f3f
24+
#define INFLL 0x3f3f3f3f3f3f3f3f
25+
26+
#define mod 1000000007
27+
#define MAXN 200010
28+
29+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
30+
ll T,N,M,K;
31+
ll resp;
32+
bool ok;
33+
34+
void solve(ll x, ll t){
35+
36+
if(x > M) return;
37+
38+
if(x == M){
39+
ok = true;
40+
resp = t;
41+
return;
42+
}
43+
44+
solve(x *2LL,t+1);
45+
solve(x *3LL,t+1);
46+
}
47+
48+
void solve(){
49+
50+
if(N == M){
51+
cout << 0 << endl;
52+
return;
53+
}
54+
55+
if(N > M){
56+
cout << -1 << endl;
57+
return;
58+
}
59+
60+
ok = false;
61+
resp = 0;
62+
63+
solve(N,0);
64+
if(ok) cout << resp << endl;
65+
else cout << -1 << endl;
66+
}
67+
68+
int main(){
69+
70+
cin >> N >> M;
71+
72+
solve();
73+
74+
return 0;
75+
}

Codeforces/486A.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
5+
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
6+
7+
typedef long long ll;
8+
typedef long double ld;
9+
typedef pair<int,int> pii;
10+
11+
#define optimize ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define endl "\n"
13+
14+
#define fi first
15+
#define se second
16+
#define pb push_back
17+
18+
#define sz(x) (ll)(x.size())
19+
#define all(x) x.begin(),x.end()
20+
#define FOR(x,a,n) for(int x= (int)(a);(x) < int(n);(x)++)
21+
#define ms(x,a) memset(x,a,sizeof(x))
22+
23+
#define INF 0x3f3f3f3f
24+
#define INFLL 0x3f3f3f3f3f3f3f3f
25+
26+
#define mod 1000000007
27+
#define MAXN 200010
28+
29+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
30+
ll T,N,M,K;
31+
32+
void solve(){
33+
34+
ll aux = (N+1)/2;
35+
36+
if(N&1){
37+
cout << -aux << endl;
38+
}else{
39+
cout << aux << endl;
40+
}
41+
42+
43+
}
44+
45+
int main(){
46+
47+
cin >> N;
48+
49+
solve();
50+
51+
return 0;
52+
}

Codeforces/628B.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
5+
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
6+
7+
typedef long long ll;
8+
typedef long double ld;
9+
typedef pair<int,int> pii;
10+
11+
#define optimize ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define endl "\n"
13+
14+
#define fi first
15+
#define se second
16+
#define pb push_back
17+
18+
#define sz(x) (ll)(x.size())
19+
#define all(x) x.begin(),x.end()
20+
#define FOR(x,a,n) for(int x= (int)(a);(x) < int(n);(x)++)
21+
#define ms(x,a) memset(x,a,sizeof(x))
22+
23+
#define INF 0x3f3f3f3f
24+
#define INFLL 0x3f3f3f3f3f3f3f3f
25+
26+
#define mod 1000000007
27+
#define MAXN 200010
28+
29+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
30+
ll T,N,M,K;
31+
string s;
32+
33+
void solve(){
34+
35+
ll ans = 0;
36+
int aux = 0;
37+
38+
for(int i = sz(s)-1;i>=0;i--){
39+
40+
if(i == sz(s)-1) {
41+
aux += (s[i] - '0');
42+
continue;
43+
}else{
44+
aux += 10*(s[i] - '0');
45+
}
46+
47+
bool ok = false;
48+
if(aux%4 == 0) {
49+
ans += i+1;
50+
ok = true;
51+
}
52+
53+
if((aux%10)%4 == 0) ans++;
54+
55+
if(i != sz(s)-1) aux = aux/10;
56+
}
57+
58+
if(aux%4 == 0) ans++;
59+
60+
cout << ans << endl;
61+
}
62+
63+
int main(){
64+
65+
cin >> s;
66+
67+
solve();
68+
69+
return 0;
70+
}

Codeforces/705A.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
5+
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
6+
7+
typedef long long ll;
8+
typedef long double ld;
9+
typedef pair<int,int> pii;
10+
11+
#define optimize ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define endl "\n"
13+
14+
#define fi first
15+
#define se second
16+
#define pb push_back
17+
18+
#define sz(x) (ll)(x.size())
19+
#define all(x) x.begin(),x.end()
20+
#define FOR(x,a,n) for(int x= (int)(a);(x) < int(n);(x)++)
21+
#define ms(x,a) memset(x,a,sizeof(x))
22+
23+
#define INF 0x3f3f3f3f
24+
#define INFLL 0x3f3f3f3f3f3f3f3f
25+
26+
#define mod 1000000007
27+
#define MAXN 200010
28+
29+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
30+
ll T,N,M,K;
31+
32+
void solve(){
33+
34+
FOR(i,0,N){
35+
if(!i){
36+
cout << "I hate ";
37+
}
38+
else if(i%2){
39+
cout << "that I love ";
40+
}else{
41+
cout << "that I hate ";
42+
}
43+
}
44+
cout << "it\n";
45+
}
46+
47+
int main(){
48+
49+
cin >> N;
50+
51+
solve();
52+
53+
return 0;
54+
}

0 commit comments

Comments
 (0)