Skip to content

Commit 97a6ec3

Browse files
committed
Edu Round 93
1 parent 0e9f94d commit 97a6ec3

File tree

13 files changed

+1554
-0
lines changed

13 files changed

+1554
-0
lines changed

CodeForces/Contest/Edu Round 93/A.cpp

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/** Which of the favors of your Lord will you deny ? **/
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
6+
#define LL long long
7+
#define PII pair<int,int>
8+
#define PLL pair<LL,LL>
9+
#define F first
10+
#define S second
11+
12+
#define ALL(x) (x).begin(), (x).end()
13+
#define READ freopen("alu.txt", "r", stdin)
14+
#define WRITE freopen("vorta.txt", "w", stdout)
15+
16+
#ifndef ONLINE_JUDGE
17+
#define DBG(x) cout << __LINE__ << " says: " << #x << " = " << (x) << endl
18+
#else
19+
#define DBG(x)
20+
#endif
21+
22+
template<class T1, class T2>
23+
ostream &operator <<(ostream &os, pair<T1,T2>&p);
24+
template <class T>
25+
ostream &operator <<(ostream &os, vector<T>&v);
26+
template <class T>
27+
ostream &operator <<(ostream &os, set<T>&v);
28+
29+
inline void optimizeIO()
30+
{
31+
ios_base::sync_with_stdio(false);
32+
cin.tie(NULL);
33+
}
34+
35+
const int nmax = 2e5+7;
36+
37+
int main()
38+
{
39+
optimizeIO();
40+
41+
int tc;
42+
cin>>tc;
43+
44+
while(tc--)
45+
{
46+
int n;
47+
cin>>n;
48+
49+
vector<PII>v(n);
50+
51+
for(int i=0;i<n;i++)
52+
cin>>v[i].F , v[i].S = i;
53+
54+
sort(ALL(v));
55+
56+
if(v[n-1].F>=v[0].F+v[1].F) cout<<v[0].S+1<<" "<<v[1].S+1<<" "<<v[n-1].S+1<<endl;
57+
else cout<<-1<<endl;
58+
}
59+
60+
return 0;
61+
}
62+
63+
/**
64+
65+
**/
66+
67+
template<class T1, class T2>
68+
ostream &operator <<(ostream &os, pair<T1,T2>&p)
69+
{
70+
os<<"{"<<p.first<<", "<<p.second<<"} ";
71+
return os;
72+
}
73+
template <class T>
74+
ostream &operator <<(ostream &os, vector<T>&v)
75+
{
76+
os<<"[ ";
77+
for(int i=0; i<v.size(); i++)
78+
{
79+
os<<v[i]<<" " ;
80+
}
81+
os<<" ]";
82+
return os;
83+
}
84+
85+
template <class T>
86+
ostream &operator <<(ostream &os, set<T>&v)
87+
{
88+
os<<"[ ";
89+
for(T i:v)
90+
{
91+
os<<i<<" ";
92+
}
93+
os<<" ]";
94+
return os;
95+
}
96+

CodeForces/Contest/Edu Round 93/B.cpp

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
2+
/** Which of the favors of your Lord will you deny ? **/
3+
4+
#include<bits/stdc++.h>
5+
using namespace std;
6+
7+
#define LL long long
8+
#define PII pair<int,int>
9+
#define PLL pair<LL,LL>
10+
#define F first
11+
#define S second
12+
13+
#define ALL(x) (x).begin(), (x).end()
14+
#define READ freopen("alu.txt", "r", stdin)
15+
#define WRITE freopen("vorta.txt", "w", stdout)
16+
17+
#ifndef ONLINE_JUDGE
18+
#define DBG(x) cout << __LINE__ << " says: " << #x << " = " << (x) << endl
19+
#else
20+
#define DBG(x)
21+
#endif
22+
23+
template<class T1, class T2>
24+
ostream &operator <<(ostream &os, pair<T1,T2>&p);
25+
template <class T>
26+
ostream &operator <<(ostream &os, vector<T>&v);
27+
template <class T>
28+
ostream &operator <<(ostream &os, set<T>&v);
29+
30+
inline void optimizeIO()
31+
{
32+
ios_base::sync_with_stdio(false);
33+
cin.tie(NULL);
34+
}
35+
36+
const int nmax = 2e5+7;
37+
38+
int main()
39+
{
40+
optimizeIO();
41+
42+
int tc;
43+
cin>>tc;
44+
45+
while(tc--)
46+
{
47+
string s;
48+
cin>>s;
49+
50+
int n = s.size();
51+
52+
s = s + "#";
53+
54+
int c = 1;
55+
56+
vector<int>v;
57+
58+
for(int i=1;i<=n;i++)
59+
{
60+
if(s[i]==s[i-1]) c++;
61+
else
62+
{
63+
if(s[i-1]=='1')
64+
{
65+
v.push_back(c);
66+
}
67+
68+
c = 1;
69+
}
70+
}
71+
72+
DBG(v);
73+
74+
sort(ALL(v));
75+
reverse(ALL(v));
76+
77+
n = v.size();
78+
79+
int ans = 0;
80+
81+
for(int i=0;i<n;i+=2)
82+
ans += v[i];
83+
84+
cout<<ans<<endl;
85+
}
86+
87+
return 0;
88+
}
89+
90+
/**
91+
92+
**/
93+
94+
template<class T1, class T2>
95+
ostream &operator <<(ostream &os, pair<T1,T2>&p)
96+
{
97+
os<<"{"<<p.first<<", "<<p.second<<"} ";
98+
return os;
99+
}
100+
template <class T>
101+
ostream &operator <<(ostream &os, vector<T>&v)
102+
{
103+
os<<"[ ";
104+
for(int i=0; i<v.size(); i++)
105+
{
106+
os<<v[i]<<" " ;
107+
}
108+
os<<" ]";
109+
return os;
110+
}
111+
112+
template <class T>
113+
ostream &operator <<(ostream &os, set<T>&v)
114+
{
115+
os<<"[ ";
116+
for(T i:v)
117+
{
118+
os<<i<<" ";
119+
}
120+
os<<" ]";
121+
return os;
122+
}
123+
124+

CodeForces/Contest/Edu Round 93/C.cpp

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
2+
/** Which of the favors of your Lord will you deny ? **/
3+
4+
#include<bits/stdc++.h>
5+
using namespace std;
6+
7+
#define LL long long
8+
#define PII pair<int,int>
9+
#define PLL pair<LL,LL>
10+
#define F first
11+
#define S second
12+
13+
#define ALL(x) (x).begin(), (x).end()
14+
#define READ freopen("alu.txt", "r", stdin)
15+
#define WRITE freopen("vorta.txt", "w", stdout)
16+
17+
#ifndef ONLINE_JUDGE
18+
#define DBG(x) cout << __LINE__ << " says: " << #x << " = " << (x) << endl
19+
#else
20+
#define DBG(x)
21+
#endif
22+
23+
template<class T1, class T2>
24+
ostream &operator <<(ostream &os, pair<T1,T2>&p);
25+
template <class T>
26+
ostream &operator <<(ostream &os, vector<T>&v);
27+
template <class T>
28+
ostream &operator <<(ostream &os, set<T>&v);
29+
30+
inline void optimizeIO()
31+
{
32+
ios_base::sync_with_stdio(false);
33+
cin.tie(NULL);
34+
}
35+
36+
const int nmax = 2e5+7;
37+
38+
int main()
39+
{
40+
optimizeIO();
41+
42+
int tc;
43+
cin>>tc;
44+
45+
while(tc--)
46+
{
47+
int n;
48+
cin>>n;
49+
50+
vector<int>p(n+1,0);
51+
52+
string s;
53+
cin>>s;
54+
55+
for(int i=1;i<=n;i++)
56+
p[i] = s[i-1] - '0';
57+
58+
for(int i=1;i<=n;i++) p[i] += p[i-1];
59+
60+
map<int,int>m;
61+
62+
LL ans = 0;
63+
for(int i=1;i<=n;i++)
64+
{
65+
int left = i - p[i-1];
66+
m[left]++;
67+
68+
int right = i - p[i] + 1;
69+
ans += m[right];
70+
}
71+
72+
cout<<ans<<endl;
73+
DBG(ans);
74+
}
75+
76+
return 0;
77+
}
78+
79+
/**
80+
81+
**/
82+
83+
template<class T1, class T2>
84+
ostream &operator <<(ostream &os, pair<T1,T2>&p)
85+
{
86+
os<<"{"<<p.first<<", "<<p.second<<"} ";
87+
return os;
88+
}
89+
template <class T>
90+
ostream &operator <<(ostream &os, vector<T>&v)
91+
{
92+
os<<"[ ";
93+
for(int i=0; i<v.size(); i++)
94+
{
95+
os<<v[i]<<" " ;
96+
}
97+
os<<" ]";
98+
return os;
99+
}
100+
101+
template <class T>
102+
ostream &operator <<(ostream &os, set<T>&v)
103+
{
104+
os<<"[ ";
105+
for(T i:v)
106+
{
107+
os<<i<<" ";
108+
}
109+
os<<" ]";
110+
return os;
111+
}
112+
113+

0 commit comments

Comments
 (0)