Skip to content

Commit 0c226f9

Browse files
committed
2019 Function Cup (oj.uz) for just the first 2 hours
1 parent 399f2ae commit 0c226f9

23 files changed

+417
-0
lines changed

Diff for: oj.uz/2019-function-cup/chairs/compile.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
problem=chairs
4+
5+
g++-7 -Wall -lm -static -DEVAL -o "${problem}" -O2 "grader.cpp" "king.cpp" "vassal.cpp"

Diff for: oj.uz/2019-function-cup/chairs/grader.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "king.h"
4+
#include "vassal.h"
5+
6+
static int N, chk[101010];
7+
static std::vector<int> W, C;
8+
9+
static void my_assert(int TF, const char* message){
10+
if(!TF){ puts(message); exit(0); }
11+
}
12+
13+
int main(){
14+
my_assert(scanf("%d", &N) == 1, "Error: Invalid Input");
15+
my_assert(1 <= N && N <= 100000, "Error: Invalid Input");
16+
17+
W.resize(N);
18+
for(int i = 0; i < N; i++){
19+
my_assert(scanf("%d", &W[i]) == 1, "Error: Invalid Input");
20+
my_assert(1 <= W[i] && W[i] <= 1000000, "Error: Invalid Input");
21+
}
22+
23+
C.resize(N);
24+
for(int i = 0; i < N; i++){
25+
my_assert(scanf("%d", &C[i]) == 1, "Error: Invalid Input");
26+
my_assert(1 <= C[i] && C[i] <= 1000000, "Error: Invalid Input");
27+
if(i) my_assert(C[i-1] <= C[i], "Error: Invalid Input");
28+
}
29+
30+
long long num = SendInfo(W, C);
31+
my_assert(0 <= num && num < (1ll << 60), "Wrong[1] : Invalid Number");
32+
33+
int chair_cnt = 0;
34+
Init(num, C);
35+
for(int i = 0; i < N; i++){
36+
int ci = Maid(W[i]);
37+
my_assert(-1 <= ci && ci < N, "Wrong[2] : Invalid Chair Number");
38+
my_assert(-1 == ci || !chk[ci], "Wrong[2] : Invalid Chair Number");
39+
my_assert(-1 == ci || W[i] <= C[ci], "Wrong[2] : Invalid Chair");
40+
chk[ci] = 1;
41+
if(ci >= 0) chair_cnt++;
42+
}
43+
44+
printf("Correct\n%d\n", chair_cnt);
45+
return 0;
46+
}

Diff for: oj.uz/2019-function-cup/chairs/king.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "king.h"
2+
3+
long long SendInfo(std::vector<int> W, std::vector<int> C) {
4+
int N = W.size();
5+
return 0;
6+
}

Diff for: oj.uz/2019-function-cup/chairs/king.h

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include <vector>
2+
long long SendInfo(std::vector<int> W, std::vector<int> C);

Diff for: oj.uz/2019-function-cup/chairs/vassal.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "vassal.h"
2+
3+
#include <bits/stdc++.h>
4+
5+
using namespace std;
6+
7+
8+
set<pair<int, int>> st;
9+
void Init(long long B, std::vector<int> C){
10+
int N = C.size();
11+
for (int i = 0; i < N; ++i) {
12+
st.insert(make_pair(C[i], i));
13+
}
14+
}
15+
16+
int Maid(int W){
17+
auto it = st.lower_bound(make_pair(W, -1));
18+
if (it == st.end())
19+
return -1;
20+
int ret = it->second;
21+
st.erase(it);
22+
return ret;
23+
}

Diff for: oj.uz/2019-function-cup/chairs/vassal.h

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <vector>
2+
void Init(long long B, std::vector<int> C);
3+
int Maid(int W);
4+

Diff for: oj.uz/2019-function-cup/cross/compile.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
problem=cross
4+
5+
g++-7 -Wall -lm -static -DEVAL -o "${problem}" -O2 "grader.cpp" "${problem}.cpp"

Diff for: oj.uz/2019-function-cup/cross/cross.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "cross.h"
2+
#include <bits/stdc++.h>
3+
4+
using namespace std;
5+
6+
long long SelectCross(int K, std::vector<int> I, std::vector<int> O) {
7+
int N = I.size();
8+
vector<pair<int, int>> pairs(N);
9+
for (int i = 0; i < N; ++i) {
10+
pairs[i] = {I[i], O[i]};
11+
}
12+
sort(pairs.begin(), pairs.end());
13+
reverse(pairs.begin(), pairs.end());
14+
priority_queue<int> pq;
15+
long long ans = 0;
16+
for (int i = 0; i < N; ++i) {
17+
pq.push(-pairs[i].second);
18+
while (pq.size() > K) {
19+
pq.pop();
20+
}
21+
if (pq.size() == K) {
22+
int din = pairs[i].first, dout = -pq.top();
23+
ans = max(ans, 1LL * dout * dout - 1LL * (dout - din) * (dout - din));
24+
}
25+
}
26+
return ans;
27+
}

Diff for: oj.uz/2019-function-cup/cross/cross.h

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include <vector>
2+
long long SelectCross(int K, std::vector<int> I, std::vector<int> O);

Diff for: oj.uz/2019-function-cup/cross/grader.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "cross.h"
4+
5+
static int N, K;
6+
static std::vector<int> In, Out;
7+
8+
static void my_assert(int TF, const char* message){
9+
if(!TF){ puts(message); exit(1); }
10+
}
11+
12+
int main(){
13+
my_assert(scanf("%d%d", &N, &K) == 2, "Error: Invalid Input");
14+
my_assert(1 <= K && K <= N && N <= 200000, "Error: Invalid Input");
15+
16+
for(int i=0; i<N; i++){
17+
int a;
18+
my_assert(scanf("%d", &a) == 1, "Error: Invalid Input");
19+
my_assert(1 <= a && a <= 1000000000, "Error: Invalid Input");
20+
In.push_back(a);
21+
}
22+
for(int i=0; i<N; i++){
23+
int a;
24+
my_assert(scanf("%d", &a) == 1, "Error: Invalid Input");
25+
my_assert(In[i] < a && a <= 1000000000, "Error: Invalid Input");
26+
Out.push_back(a);
27+
}
28+
29+
printf("%lld\n", SelectCross(K, In, Out));
30+
return 0;
31+
}

Diff for: oj.uz/2019-function-cup/hiccup/compile.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
problem=hiccup
4+
5+
g++ -Wall -lm -static -DEVAL -o "${problem}" -O2 "grader.cpp" "${problem}.cpp"

Diff for: oj.uz/2019-function-cup/hiccup/grader.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include "hiccup.h"
5+
6+
static char st[1000101]; static int len;
7+
8+
static void my_assert(int TF, const char* message){
9+
if(!TF){ puts(message); exit(0); }
10+
}
11+
12+
int main(){
13+
my_assert(scanf("%s", st) == 1, "Error: Invalid Input");
14+
len = strlen(st);
15+
my_assert(1 <= len && len <= 1000000, "Error: Invalid Input");
16+
17+
for(int i=0; i<len; i++){
18+
my_assert(st[i]=='H' || st[i]=='C' || st[i]=='!', "Error: Invalid Input");
19+
}
20+
21+
std::string ss = st;
22+
printf("%d\n", HicCup(ss));
23+
return 0;
24+
}

Diff for: oj.uz/2019-function-cup/hiccup/hiccup.cpp

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include "hiccup.h"
2+
3+
#include <bits/stdc++.h>
4+
5+
using namespace std;
6+
7+
bool can(string & S, int & it, int x) {
8+
int cnt = 0, need = 0;
9+
while (it < S.size()) {
10+
if (cnt > 0 && need == 0) {
11+
--cnt;
12+
need = x;
13+
}
14+
char ch = S[it++];
15+
if (ch == '!') {
16+
if (need > 0) {
17+
--need;
18+
}
19+
}
20+
else if (ch == 'H') {
21+
bool res = can(S, it, x);
22+
if (!res)
23+
return false;
24+
++cnt;
25+
}
26+
else {
27+
return cnt <= 0 && need <= 0;
28+
}
29+
}
30+
return cnt <= 0 && need <= 0;
31+
}
32+
33+
int HicCup(std::string S) {
34+
int N = S.size();
35+
int open = 0;
36+
for (int i = 0; i < N; ++i) {
37+
if (S[i] == 'H')
38+
++open;
39+
else if (S[i] == 'C')
40+
--open;
41+
if (open < 0)
42+
return -1;
43+
}
44+
if (open != 0)
45+
return -1;
46+
if (S[0] == '!')
47+
return -1;
48+
for (int i = 0; i + 1 < N; ++i) {
49+
if (S[i] == 'H' && S[i+1] == '!')
50+
return -1;
51+
}
52+
int low = 0, hi = N;
53+
while (low < hi) {
54+
int mid = (low + hi + 1) >> 1;
55+
int it = 0;
56+
if (can(S, it, mid))
57+
low = mid;
58+
else
59+
hi = mid-1;
60+
}
61+
return low;
62+
}

Diff for: oj.uz/2019-function-cup/hiccup/hiccup.h

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include <string>
2+
int HicCup(std::string S);

Diff for: oj.uz/2019-function-cup/museum/compile.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
problem=museum
4+
5+
g++-7 -Wall -lm -static -DEVAL -o "${problem}" -O2 "grader.cpp" "${problem}.cpp"

Diff for: oj.uz/2019-function-cup/museum/grader.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "museum.h"
4+
5+
static int N;
6+
static std::vector<int> Badge, Tshirt, Gift;
7+
8+
static void my_assert(int TF, const char* message){
9+
if(!TF){ puts(message); exit(1); }
10+
}
11+
12+
int main(){
13+
my_assert(scanf("%d", &N) == 1, "Error: Invalid Input");
14+
my_assert(2 <= N && N <= 200000, "Error: Invalid Input");
15+
16+
for(int i=0; i<N; i++){
17+
int a;
18+
my_assert(scanf("%d", &a) == 1, "Error: Invalid Input");
19+
my_assert(1 <= a && a <= 100, "Error: Invalid Input");
20+
Badge.push_back(a);
21+
}
22+
for(int i=0; i<N; i++){
23+
int a;
24+
my_assert(scanf("%d", &a) == 1, "Error: Invalid Input");
25+
my_assert(1 <= a && a <= 100, "Error: Invalid Input");
26+
Tshirt.push_back(a);
27+
}
28+
for(int i=0; i<N; i++){
29+
int a;
30+
my_assert(scanf("%d", &a) == 1, "Error: Invalid Input");
31+
my_assert(1 <= a && a <= 100, "Error: Invalid Input");
32+
Gift.push_back(a);
33+
}
34+
35+
printf("%lld\n", CountSimilarPairs(Badge, Tshirt, Gift));
36+
return 0;
37+
}

Diff for: oj.uz/2019-function-cup/museum/museum.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "museum.h"
2+
#include <bits/stdc++.h>
3+
4+
using namespace std;
5+
6+
7+
template<typename T>
8+
long long calc(vector<T> v) {
9+
sort(v.begin(), v.end());
10+
long long ans = 0;
11+
int cnt = 0;
12+
T last = v[0];
13+
for (int i = 0; i < (int)v.size(); ++i) {
14+
if (last != v[i]) {
15+
ans += 1L * cnt * (cnt - 1) / 2;
16+
cnt = 0;
17+
last = v[i];
18+
}
19+
++cnt;
20+
}
21+
ans += 1LL * cnt * (cnt - 1) / 2;
22+
return ans;
23+
}
24+
25+
template<typename T>
26+
long long calc2(vector<T> A, vector<T> B) {
27+
vector<pair<T, T>> v(A.size());
28+
for (int i = 0; i < (int)v.size(); ++i)
29+
v[i] = {A[i], B[i]};
30+
return calc(v);
31+
}
32+
33+
template<typename T>
34+
long long calc3(vector<T> A, vector<T> B, vector<T> C) {
35+
vector<tuple<T, T, T>> v(A.size());
36+
for (int i = 0; i < (int)v.size(); ++i)
37+
v[i] = {A[i], B[i], C[i]};
38+
return calc(v);
39+
}
40+
41+
long long CountSimilarPairs(std::vector<int> B, std::vector<int> T, std::vector<int> G) {
42+
return calc(B) + calc(T) + calc(G) - calc2(B, T) - calc2(B, G) - calc2(T, G) + calc3(B, T, G);
43+
}

Diff for: oj.uz/2019-function-cup/museum/museum.h

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include <vector>
2+
long long CountSimilarPairs(std::vector<int> B, std::vector<int> T, std::vector<int> G);

Diff for: oj.uz/2019-function-cup/prepare.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
name="$1"
4+
mkdir $name
5+
cd $name
6+
mv ~/Downloads/Compressed/grader.zip .
7+
unzip grader.zip

Diff for: oj.uz/2019-function-cup/unique/compile.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
problem=unique
4+
5+
g++-7 -Wall -lm -static -DEVAL -o "${problem}" -O2 "grader.cpp" "${problem}.cpp"

0 commit comments

Comments
 (0)