Skip to content

Commit 9913345

Browse files
author
Pratyush Raj
authored
IARCS OPC JUDGE
Solution to some of the IARCS OPC JUDGE Problems solved in C++
1 parent bbcab37 commit 9913345

14 files changed

+1401
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
https://www.codechef.com/IARCSJUD/problems/AVERAGE/
3+
*/
4+
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
8+
// <-- Template code for utility -->
9+
#define watch(x) cout << (#x) << " is " << (x) << endl
10+
#define forl(i, b, e) for (i = b; i < e; i++)
11+
#define fore(i, b, e) for (i = b; i <= e; i++)
12+
13+
void input_arr(vector<int> &arr, int n)
14+
{
15+
int i;
16+
forl(i, 0, n)
17+
{
18+
int num;
19+
cin>>num;
20+
arr.push_back(num);
21+
}
22+
}
23+
24+
template <typename T1, typename T2>
25+
inline std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p)
26+
{
27+
return os << "(" << p.first << ", " << p.second << ")";
28+
}
29+
30+
template <typename T>
31+
inline std::ostream &operator<<(std::ostream &os, const std::vector<T> &v)
32+
{
33+
bool first = true;
34+
os << "[";
35+
for (unsigned int i = 0; i < v.size(); i++)
36+
{
37+
if (!first)
38+
os << ", ";
39+
os << v[i];
40+
first = false;
41+
}
42+
return os << "]";
43+
}
44+
45+
template <typename T>
46+
inline std::ostream &operator<<(std::ostream &os, const std::set<T> &v)
47+
{
48+
bool first = true;
49+
os << "[";
50+
for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
51+
{
52+
if (!first)
53+
os << ", ";
54+
os << *ii;
55+
first = false;
56+
}
57+
return os << "]";
58+
}
59+
60+
template <typename T1, typename T2>
61+
inline std::ostream &operator<<(std::ostream &os, const std::map<T1, T2> &v)
62+
{
63+
bool first = true;
64+
os << "[";
65+
for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
66+
{
67+
if (!first)
68+
os << ", ";
69+
os << *ii;
70+
first = false;
71+
}
72+
return os << "]";
73+
}
74+
75+
// <-- Main funtion -->
76+
// This is where the actual program is
77+
78+
int main(int argc, char *argv[])
79+
{
80+
// <-- Fast I/O -->
81+
ios_base::sync_with_stdio(false);
82+
cin.tie(0);
83+
int t = 1;
84+
// <-- Multiple test cases -->
85+
// cin>>t;
86+
while (t--) {
87+
int n;
88+
cin>>n;
89+
unordered_map<int, int> twice;
90+
vector<int> nums;
91+
input_arr(nums, n);
92+
int i, j;
93+
forl(i, 0, n) {
94+
twice[nums[i]*2] = 1;
95+
}
96+
int count = 0;
97+
forl(i, 0, n-1) {
98+
forl(j, i+1, n) {
99+
count += (twice[nums[i] + nums[j]]) + (nums[i] == nums[j]);
100+
twice[nums[i] + nums[j]] = 0;
101+
}
102+
}
103+
cout<<count<<"\n";
104+
}
105+
return 0;
106+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
https://www.codechef.com/IARCSJUD/problems/VOTERSDI
3+
*/
4+
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
8+
// <-- Template code for utility -->
9+
#define watch(x) cout << (#x) << " is " << (x) << endl
10+
#define forl(i, b, e) for (i = b; i < e; i++)
11+
#define fore(i, b, e) for (i = b; i <= e; i++)
12+
13+
void input_arr(vector<int> &arr, int n)
14+
{
15+
int i;
16+
forl(i, 0, n)
17+
{
18+
int num;
19+
cin>>num;
20+
arr.push_back(num);
21+
}
22+
}
23+
24+
template <typename T1, typename T2>
25+
inline std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p)
26+
{
27+
return os << "(" << p.first << ", " << p.second << ")";
28+
}
29+
30+
template <typename T>
31+
inline std::ostream &operator<<(std::ostream &os, const std::vector<T> &v)
32+
{
33+
bool first = true;
34+
os << "[";
35+
for (unsigned int i = 0; i < v.size(); i++)
36+
{
37+
if (!first)
38+
os << ", ";
39+
os << v[i];
40+
first = false;
41+
}
42+
return os << "]";
43+
}
44+
45+
template <typename T>
46+
inline std::ostream &operator<<(std::ostream &os, const std::set<T> &v)
47+
{
48+
bool first = true;
49+
os << "[";
50+
for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
51+
{
52+
if (!first)
53+
os << ", ";
54+
os << *ii;
55+
first = false;
56+
}
57+
return os << "]";
58+
}
59+
60+
template <typename T1, typename T2>
61+
inline std::ostream &operator<<(std::ostream &os, const std::map<T1, T2> &v)
62+
{
63+
bool first = true;
64+
os << "[";
65+
for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
66+
{
67+
if (!first)
68+
os << ", ";
69+
os << *ii;
70+
first = false;
71+
}
72+
return os << "]";
73+
}
74+
75+
// <-- Main funtion -->
76+
// This is where the actual program is
77+
78+
int main(int argc, char *argv[])
79+
{
80+
// <-- Fast I/O -->
81+
ios_base::sync_with_stdio(false);
82+
cin.tie(0);
83+
int t = 1;
84+
// <-- Multiple test cases -->
85+
// cin>>t;
86+
while (t--) {
87+
int n1, n2, n3, i, j;
88+
cin>>n1>>n2>>n3;
89+
90+
int n = n1+n2+n3;
91+
map<int, int> voters;
92+
93+
forl(i, 0, n) {
94+
int input;
95+
cin>>input;
96+
voters[input]++;
97+
}
98+
99+
vector<int> final_list;
100+
for(auto i = voters.begin();i != voters.end();i++) {
101+
if(i->second >= 2)
102+
final_list.push_back(i->first);
103+
}
104+
105+
cout<<final_list.size()<<"\n";
106+
107+
forl(i, 0, final_list.size())
108+
cout<<final_list[i]<<"\n";
109+
}
110+
return 0;
111+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
https://www.codechef.com/IARCSJUD/problems/DIVSEQ/
3+
*/
4+
5+
#include<bits/stdc++.h>
6+
using namespace std;
7+
int main(){
8+
int n; cin>>n;
9+
int seq[n];
10+
for(int i=0;i<n;i++){
11+
cin>>seq[i];
12+
}
13+
int flag[n];
14+
flag[0]=1;
15+
for(int i =1;i<n;i++){
16+
flag[i]=1;
17+
for(int j=0;j<i;j++){
18+
if(seq[i]%seq[j]==0 && flag[j] != 0){
19+
flag[i]=max(flag[i],flag[j]+1);
20+
}
21+
}
22+
}
23+
cout<<*max_element(flag,flag+n);
24+
return 0;
25+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
https://www.codechef.com/IARCSJUD/problems/ENDCORR/
3+
*/
4+
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
8+
// <-- Template code for utility -->
9+
#define watch(x) cout << (#x) << " is " << (x) << endl
10+
#define forl(i, b, e) for (i = b; i < e; i++)
11+
#define fore(i, b, e) for (i = b; i <= e; i++)
12+
13+
void input_arr(vector<int> &arr, int n)
14+
{
15+
int i;
16+
forl(i, 0, n)
17+
{
18+
int num;
19+
cin>>num;
20+
arr.push_back(num);
21+
}
22+
}
23+
24+
template <typename T1, typename T2>
25+
inline std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p)
26+
{
27+
return os << "(" << p.first << ", " << p.second << ")";
28+
}
29+
30+
template <typename T>
31+
inline std::ostream &operator<<(std::ostream &os, const std::vector<T> &v)
32+
{
33+
bool first = true;
34+
os << "[";
35+
for (unsigned int i = 0; i < v.size(); i++)
36+
{
37+
if (!first)
38+
os << ", ";
39+
os << v[i];
40+
first = false;
41+
}
42+
return os << "]";
43+
}
44+
45+
template <typename T>
46+
inline std::ostream &operator<<(std::ostream &os, const std::set<T> &v)
47+
{
48+
bool first = true;
49+
os << "[";
50+
for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
51+
{
52+
if (!first)
53+
os << ", ";
54+
os << *ii;
55+
first = false;
56+
}
57+
return os << "]";
58+
}
59+
60+
template <typename T1, typename T2>
61+
inline std::ostream &operator<<(std::ostream &os, const std::map<T1, T2> &v)
62+
{
63+
bool first = true;
64+
os << "[";
65+
for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
66+
{
67+
if (!first)
68+
os << ", ";
69+
os << *ii;
70+
first = false;
71+
}
72+
return os << "]";
73+
}
74+
75+
// <-- Main funtion -->
76+
// This is where the actual program is
77+
78+
int main(int argc, char *argv[])
79+
{
80+
// <-- Fast I/O -->
81+
ios_base::sync_with_stdio(false);
82+
cin.tie(0);
83+
int t = 1;
84+
// <-- Multiple test cases -->
85+
// cin>>t;
86+
while (t--) {
87+
int n, m, i;
88+
cin>>n>>m;
89+
vector<int> citizens;
90+
make_heap(citizens.begin(), citizens.end());
91+
forl(i, 0, n+m) {
92+
int input;
93+
cin>>input;
94+
95+
if(input < 0) {
96+
cout<<citizens.front()<<"\n";
97+
pop_heap(citizens.begin(), citizens.end());
98+
citizens.pop_back();
99+
}
100+
101+
else {
102+
citizens.push_back(input);
103+
push_heap(citizens.begin(), citizens.end());
104+
}
105+
}
106+
}
107+
return 0;
108+
}

0 commit comments

Comments
 (0)