Skip to content

Commit 6561a9b

Browse files
committed
Added more
1 parent d1bf8c8 commit 6561a9b

File tree

11 files changed

+383
-21
lines changed

11 files changed

+383
-21
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define int long long int
4+
#define pb push_back
5+
#define pll pair<int, int>
6+
const int modll = 1e17;
7+
const int mod = 1e9 + 7;
8+
const int INF = 1e18;
9+
int dx[] = {1, 0, -1, 0};
10+
int dy[] = {0, 1, 0, -1};
11+
vector<int> seive(int n) { vector<int> prime(n+1, 1); for(int i=2; i*i<=n; i++) if(prime[i]) for(int j=i*i; j<=n; j+=i) prime[j]=0; return prime; }
12+
template <typename T> void takeInput(vector<T> &a, int n) { for(int i=0; i<n; i++) { T ele; cin>>ele; a[i]=ele; } }
13+
template <typename T> void printArr(vector<T> &a) { for(auto it:a) cout<<it<<" "; cout<<endl; }
14+
int fastPow(int a, int b) { int res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; }
15+
16+
void solve(){
17+
int n ;
18+
cin >> n;
19+
20+
if (n == 1) {
21+
cout << 1 << endl;
22+
cout << 1 << endl;
23+
} else {
24+
int k = n / 2;
25+
cout << k << endl;
26+
for (int i = 1; i <= k; ++i) {
27+
cout << 2 * i;
28+
if (i != k) cout << " ";
29+
}
30+
cout << endl;
31+
}
32+
33+
34+
}
35+
int32_t main(){
36+
ios_base::sync_with_stdio(false);
37+
cin.tie(NULL);
38+
cout.tie(NULL);
39+
auto start = chrono::high_resolution_clock::now();
40+
int t = 1;
41+
// cin >> t;
42+
while(t--){
43+
solve();
44+
}
45+
auto end = chrono::high_resolution_clock::now();
46+
auto elapsed = chrono::duration_cast<chrono::nanoseconds>(end - start);
47+
cerr << fixed << setprecision(10) << "Time measured: " << static_cast<double>(elapsed.count()) * 1e-9 << " seconds.\n";
48+
return 0;
49+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define int long long int
4+
#define pb push_back
5+
#define pll pair<int, int>
6+
const int modll = 1e17;
7+
const int mod = 1e9 + 7;
8+
const int INF = 1e18;
9+
int dx[] = {1, 0, -1, 0};
10+
int dy[] = {0, 1, 0, -1};
11+
vector<int> seive(int n) { vector<int> prime(n+1, 1); for(int i=2; i*i<=n; i++) if(prime[i]) for(int j=i*i; j<=n; j+=i) prime[j]=0; return prime; }
12+
template <typename T> void takeInput(vector<T> &a, int n) { for(int i=0; i<n; i++) { T ele; cin>>ele; a[i]=ele; } }
13+
template <typename T> void printArr(vector<T> &a) { for(auto it:a) cout<<it<<" "; cout<<endl; }
14+
int fastPow(int a, int b) { int res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; }
15+
16+
void solve(){
17+
int x,y,z;
18+
cin >> x >> y >> z ;
19+
if( z <=(x + y )/2 ) {
20+
cout << "Yes" ;
21+
}else {
22+
cout << "No" ;
23+
}
24+
cout << endl;
25+
26+
}
27+
int32_t main(){
28+
ios_base::sync_with_stdio(false);
29+
cin.tie(NULL);
30+
cout.tie(NULL);
31+
auto start = chrono::high_resolution_clock::now();
32+
int t = 1;
33+
cin >> t;
34+
while(t--){
35+
solve();
36+
}
37+
auto end = chrono::high_resolution_clock::now();
38+
auto elapsed = chrono::duration_cast<chrono::nanoseconds>(end - start);
39+
cerr << fixed << setprecision(10) << "Time measured: " << static_cast<double>(elapsed.count()) * 1e-9 << " seconds.\n";
40+
return 0;
41+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define int long long int
4+
#define pb push_back
5+
#define pll pair<int, int>
6+
const int modll = 1e17;
7+
const int mod = 1e9 + 7;
8+
const int INF = 1e18;
9+
int dx[] = {1, 0, -1, 0};
10+
int dy[] = {0, 1, 0, -1};
11+
vector<int> seive(int n) { vector<int> prime(n+1, 1); for(int i=2; i*i<=n; i++) if(prime[i]) for(int j=i*i; j<=n; j+=i) prime[j]=0; return prime; }
12+
template <typename T> void takeInput(vector<T> &a, int n) { for(int i=0; i<n; i++) { T ele; cin>>ele; a[i]=ele; } }
13+
template <typename T> void printArr(vector<T> &a) { for(auto it:a) cout<<it<<" "; cout<<endl; }
14+
int fastPow(int a, int b) { int res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; }
15+
16+
void solve(){
17+
int n;
18+
cin >> n;
19+
vector<int> a(n);
20+
for (int i = 0; i < n; ++i) {
21+
cin >> a[i];
22+
}
23+
24+
if (n == 1) {
25+
cout << 0 << std::endl;
26+
return;
27+
}
28+
29+
sort(a.begin(), a.end());
30+
31+
int m = n - 1;
32+
33+
for (int i = 0; i < n; ++i) {
34+
for (int j = i; j < n; ++j) {
35+
if ((a[i] % 2) == (a[j] % 2)) {
36+
int c = i + (n - 1 - j);
37+
if (c < m) {
38+
m = c;
39+
}
40+
}
41+
}
42+
}
43+
cout << m << endl;
44+
45+
46+
}
47+
int32_t main(){
48+
ios_base::sync_with_stdio(false);
49+
cin.tie(NULL);
50+
cout.tie(NULL);
51+
auto start = chrono::high_resolution_clock::now();
52+
int t = 1;
53+
cin >> t;
54+
while(t--){
55+
solve();
56+
}
57+
auto end = chrono::high_resolution_clock::now();
58+
auto elapsed = chrono::duration_cast<chrono::nanoseconds>(end - start);
59+
cerr << fixed << setprecision(10) << "Time measured: " << static_cast<double>(elapsed.count()) * 1e-9 << " seconds.\n";
60+
return 0;
61+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define int long long int
4+
#define pb push_back
5+
#define pll pair<int, int>
6+
const int modll = 1e17;
7+
const int mod = 1e9 + 7;
8+
const int INF = 1e18;
9+
int dx[] = {1, 0, -1, 0};
10+
int dy[] = {0, 1, 0, -1};
11+
vector<int> seive(int n) { vector<int> prime(n+1, 1); for(int i=2; i*i<=n; i++) if(prime[i]) for(int j=i*i; j<=n; j+=i) prime[j]=0; return prime; }
12+
template <typename T> void takeInput(vector<T> &a, int n) { for(int i=0; i<n; i++) { T ele; cin>>ele; a[i]=ele; } }
13+
template <typename T> void printArr(vector<T> &a) { for(auto it:a) cout<<it<<" "; cout<<endl; }
14+
int fastPow(int a, int b) { int res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; }
15+
16+
void solve(){
17+
18+
string s ;
19+
cin >>s ;
20+
stack<char>st;
21+
bool ok = false;
22+
23+
for(int i=0 ;i < s.size(); i ++ ) {
24+
if(ok && s[i] == '(') {
25+
cout << "YES" << endl;
26+
return;
27+
}
28+
if(!st.empty() && s[i] == ')') {
29+
st.pop();
30+
if(st.size() == 0 )
31+
{
32+
ok = true;
33+
}
34+
35+
}else {
36+
37+
st.push('(');
38+
}
39+
40+
}
41+
cout << "NO" << endl;
42+
43+
44+
}
45+
int32_t main(){
46+
ios_base::sync_with_stdio(false);
47+
cin.tie(NULL);
48+
cout.tie(NULL);
49+
auto start = chrono::high_resolution_clock::now();
50+
int t = 1;
51+
cin >> t;
52+
while(t--){
53+
solve();
54+
}
55+
auto end = chrono::high_resolution_clock::now();
56+
auto elapsed = chrono::duration_cast<chrono::nanoseconds>(end - start);
57+
cerr << fixed << setprecision(10) << "Time measured: " << static_cast<double>(elapsed.count()) * 1e-9 << " seconds.\n";
58+
return 0;
59+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define int long long int
4+
#define pb push_back
5+
#define pll pair<int, int>
6+
const int modll = 1e17;
7+
const int mod = 1e9 + 7;
8+
const int INF = 1e18;
9+
int dx[] = {1, 0, -1, 0};
10+
int dy[] = {0, 1, 0, -1};
11+
vector<int> seive(int n) { vector<int> prime(n+1, 1); for(int i=2; i*i<=n; i++) if(prime[i]) for(int j=i*i; j<=n; j+=i) prime[j]=0; return prime; }
12+
template <typename T> void takeInput(vector<T> &a, int n) { for(int i=0; i<n; i++) { T ele; cin>>ele; a[i]=ele; } }
13+
template <typename T> void printArr(vector<T> &a) { for(auto it:a) cout<<it<<" "; cout<<endl; }
14+
int fastPow(int a, int b) { int res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; }
15+
16+
void solve() {
17+
int n;
18+
cin >> n;
19+
20+
vector<int> d(n);
21+
for (int i = 0; i < n; i ++ )
22+
cin >> d[i];
23+
24+
vector<pair<int, int>> arr(n);
25+
for (int i = 0; i < n; i ++ )
26+
cin >> arr[i].first >> arr[i].second;
27+
28+
vector<pair<int, int>> h(n + 1);
29+
h[0] = {0, 0};
30+
31+
for (int i = 0; i < n; i ++ ) {
32+
int mn = h[i].first, mx = h[i].second;
33+
int nxt_mn, nxt_mx;
34+
35+
if (d[i] == 0) {
36+
nxt_mn = mn;
37+
nxt_mx = mx;
38+
} else if (d[i] == 1) {
39+
nxt_mn = mn + 1;
40+
nxt_mx = mx + 1;
41+
} else {
42+
nxt_mn = mn;
43+
nxt_mx = mx + 1;
44+
}
45+
46+
h[i + 1].first = max(nxt_mn, arr[ i].first);
47+
h[i + 1].second = min(nxt_mx, arr[i].second);
48+
49+
if (h[i + 1].first > h[i + 1].second) {
50+
cout << -1 << endl;
51+
return;
52+
53+
54+
}
55+
}
56+
57+
vector<int> res(n);
58+
59+
60+
61+
int cur = h[n].first;
62+
63+
for (int i = n - 1; i >= 0; i -- ) {
64+
if (d[i] != -1) {
65+
res[i] = d[i];
66+
cur -= d[i];
67+
} else {
68+
int h0 = cur;
69+
if (h0 >= h[i].first && h0 <= h[i].second) {
70+
res[i] = 0;
71+
} else {
72+
res[i] = 1;
73+
cur -= 1;
74+
}
75+
76+
77+
}
78+
}
79+
80+
for (int i = 0; i < n; ++i) {
81+
cout << res[i] << " ";
82+
}
83+
cout << endl;
84+
}
85+
86+
int32_t main(){
87+
ios_base::sync_with_stdio(false);
88+
cin.tie(NULL);
89+
cout.tie(NULL);
90+
auto start = chrono::high_resolution_clock::now();
91+
int t = 1;
92+
cin >> t;
93+
while(t--){
94+
solve();
95+
}
96+
auto end = chrono::high_resolution_clock::now();
97+
auto elapsed = chrono::duration_cast<chrono::nanoseconds>(end - start);
98+
cerr << fixed << setprecision(10) << "Time measured: " << static_cast<double>(elapsed.count()) * 1e-9 << " seconds.\n";
99+
return 0;
100+
}

cses/.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cses/.idea/cses.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cses/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cses/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cses/graphs/High_Score.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,7 @@ template <typename T> void printArr(vector<T> &a) { for(auto it:a) cout<<it<<" "
1414
int fastPow(int a, int b) { int res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; }
1515

1616
void solve(){
17-
int n ,m ;
18-
cin >> n >> m ;
19-
vector<vector<int>> g [n];
20-
for(int i=0 ;i < m ;i ++ ) {
21-
int a , b ,c ;
22-
cin >>a >>b >> c ;
23-
a -- ;
24-
b -- ;
25-
g[a].push_back({b,c});
26-
}
27-
int ans= 0 ;
28-
// dist , node
29-
priority_queue<pll> pq ;
30-
pq.push({0,0 });
31-
while(!pq.empty()) {
32-
auto p = pq.top();
33-
pq.pop();
34-
35-
36-
37-
}
17+
3818
}
3919
int32_t main(){
4020
ios_base::sync_with_stdio(false);

0 commit comments

Comments
 (0)