Skip to content

Commit 132319e

Browse files
committed
added more problems solved
1 parent 48ce031 commit 132319e

File tree

149 files changed

+327113
-82
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+327113
-82
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"iostream": "cpp"
4+
}
5+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 all(x) x.begin(),x.end()
19+
#define ms(x,a) memset(x,a,sizeof(x))
20+
21+
#define INF 0x3f3f3f3f
22+
#define INFLL 0x3f3f3f3f3f3f3f3f
23+
24+
#define mod 1000000007LL
25+
#define MAXN 200010
26+
27+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
28+
29+
//#define _DEBUG
30+
// #ifdef _DEBUG
31+
// #endif
32+
33+
/* -------------------------------- Solution starts below -------------------------------- */
34+
35+
ll T,N,M,K;
36+
string s;
37+
38+
bool valid(char a, char b, char c){
39+
40+
int cnt = 0;
41+
42+
for(int i=0;i<s.size();i++){
43+
if(s[i] == 'A'){
44+
if(a == '(') cnt++;
45+
else cnt--;
46+
}
47+
else if(s[i] == 'B'){
48+
if(b == '(') cnt++;
49+
else cnt--;
50+
}
51+
else if(s[i] == 'C'){
52+
if(c == '(') cnt++;
53+
else cnt--;
54+
}
55+
56+
if(cnt < 0) return false;
57+
}
58+
59+
if(!cnt) return true;
60+
else return false;
61+
}
62+
63+
void solve(){
64+
65+
if(valid('(','(',')') || valid('(',')','(') || valid(')','(','(') || valid('(',')',')') || valid(')',')','(') || valid(')','(',')') ){
66+
cout << "YES\n";
67+
}
68+
else{
69+
cout << "NO\n";
70+
}
71+
72+
}
73+
74+
int main(){
75+
76+
optimize;
77+
78+
cin >> T;
79+
80+
while(T--){
81+
cin >> s;
82+
83+
solve();
84+
}
85+
86+
return 0;
87+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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 all(x) x.begin(),x.end()
19+
#define ms(x,a) memset(x,a,sizeof(x))
20+
21+
#define INF 0x3f3f3f3f
22+
#define INFLL 0x3f3f3f3f3f3f3f3f
23+
24+
#define mod 1000000007LL
25+
#define MAXN 200010
26+
27+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
28+
29+
//#define _DEBUG
30+
// #ifdef _DEBUG
31+
// #endif
32+
33+
/* -------------------------------- Solution starts below -------------------------------- */
34+
35+
ll T,N,M,K,U,R,L,D;
36+
37+
void solve(){
38+
39+
M = 4*N;
40+
41+
if(U == N && D == N) {
42+
if(L < 2 || R < 2){
43+
cout << "NO\n";
44+
return;
45+
}
46+
}
47+
else if( (U == N && D == N-1) || ((U == N-1 && D == N)) ){
48+
if(min(L,R) < 1 || max(L,R) < 2){
49+
cout << "NO\n";
50+
return;
51+
}
52+
}
53+
else if( U == N || D == N){
54+
if(L < 1 || R < 1){
55+
cout << "NO\n";
56+
return;
57+
}
58+
}
59+
else if( U == N-1 && D == N-1 ){
60+
if(L >= 2 || R >=2 || (L && R) );
61+
else{
62+
cout << "NO\n";
63+
return;
64+
}
65+
}
66+
else if(U == N-1 || D == N-1 ){
67+
if(L || R);
68+
else{
69+
cout << "NO\n";
70+
return;
71+
}
72+
}
73+
74+
swap(L, U);
75+
swap(R, D);
76+
77+
if(U == N && D == N) {
78+
if(L < 2 || R < 2){
79+
cout << "NO\n";
80+
return;
81+
}
82+
}
83+
else if( (U == N && D == N-1) || ((U == N-1 && D == N)) ){
84+
if(min(L,R) < 1 || max(L,R) < 2){
85+
cout << "NO\n";
86+
return;
87+
}
88+
}
89+
else if( U == N || D == N){
90+
if(L < 1 || R < 1){
91+
cout << "NO\n";
92+
return;
93+
}
94+
}
95+
else if( U == N-1 && D == N-1 ){
96+
if(L >= 2 || R >=2 || (L && R) );
97+
else{
98+
cout << "NO\n";
99+
return;
100+
}
101+
}
102+
else if(U == N-1 || D == N-1 ){
103+
if(L || R);
104+
else{
105+
cout << "NO\n";
106+
return;
107+
}
108+
}
109+
110+
cout << "YES\n";
111+
}
112+
113+
int main(){
114+
115+
optimize;
116+
117+
cin >> T;
118+
119+
while(T--){
120+
cin >> N >> U >> R >> D >> L;
121+
122+
solve();
123+
}
124+
125+
return 0;
126+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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 all(x) x.begin(),x.end()
19+
#define ms(x,a) memset(x,a,sizeof(x))
20+
21+
#define INF 0x3f3f3f3f
22+
#define INFLL 0x3f3f3f3f3f3f3f3f
23+
24+
#define mod 1000000007LL
25+
#define MAXN 200010
26+
27+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
28+
29+
//#define _DEBUG
30+
// #ifdef _DEBUG
31+
// #endif
32+
33+
/* -------------------------------- Solution starts below -------------------------------- */
34+
35+
ll T,N,M,K;
36+
vector<int> pos, pos2, esp, esp2;
37+
38+
int f(vector<int> &a, vector<int> &b){
39+
40+
if(a.empty() || b.empty()) return 0;
41+
if(a[0] > b.back()) return 0;
42+
43+
int ptr = 0, ptr2 = 0, ans = 0;
44+
vector<int> c;
45+
46+
while(ptr < a.size() && ptr2 < b.size()){
47+
if(b[ptr2] < a[ptr]) ptr2++;
48+
else if(a[ptr] < b[ptr2]) ptr++;
49+
else if(a[ptr] == b[ptr2]){
50+
c.pb(a[ptr]);
51+
ptr++;
52+
ptr2++;
53+
}
54+
}
55+
56+
ptr = 0;
57+
ans = c.size();
58+
59+
int i = 0;
60+
if(i < b.size() && b[i] < a[0]) i++;
61+
62+
for(;i<b.size();i++){
63+
while(ptr < a.size() && a[ptr] <= b[i]) ptr++;
64+
65+
while(ptr < a.size() && b[i] + ptr >= a[ptr]) ptr++;
66+
67+
int aux = 0;
68+
69+
auto it = upper_bound(all(b), b[i] + ptr - 1);
70+
it--;
71+
72+
aux = it - b.begin();
73+
aux = aux - i + 1;
74+
75+
int aux2 = upper_bound(all(c), b[i] + ptr) - c.begin();
76+
aux2 = c.size() - aux2;
77+
78+
ans = max(ans, aux + aux2);
79+
}
80+
81+
return ans;
82+
}
83+
84+
void solve(){
85+
86+
reverse(all(pos2));
87+
reverse(all(esp2));
88+
89+
int ans = f(pos, esp);
90+
ans += f(pos2, esp2);
91+
92+
cout << ans << endl;
93+
}
94+
95+
int main(){
96+
97+
optimize;
98+
99+
cin >> T;
100+
101+
while(T--){
102+
cin >> N >> M;
103+
104+
pos.clear();
105+
pos2.clear();
106+
esp.clear();
107+
esp2.clear();
108+
109+
for(int i=0;i<N;i++) {
110+
int a;
111+
112+
cin >> a;
113+
114+
if(a < 0) pos2.pb(-a);
115+
else pos.pb(a);
116+
}
117+
118+
for(int i=0;i<M;i++) {
119+
int a;
120+
121+
cin >> a;
122+
123+
if(a < 0) esp2.pb(-a);
124+
else esp.pb(a);
125+
}
126+
127+
solve();
128+
}
129+
130+
return 0;
131+
}

0 commit comments

Comments
 (0)