-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
a.out | ||
*.out | ||
tmp | ||
[0-9]* | ||
i[0-9]* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# [March Challenge 2019 Division 2](https://www.codechef.com/MARCH19B) |
62 changes: 62 additions & 0 deletions
62
code-chef/march-challenge-2019-div-2/cheating-on-queue/gab.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
#define pb push_back | ||
#define eb emplace_back | ||
#define mk make_pair | ||
#define fi first | ||
#define se second | ||
|
||
typedef long long ll; | ||
typedef pair<int, int> ii; | ||
const int INF = 0x3f3f3f3f; | ||
const double PI = acos(-1.0); | ||
|
||
const int MAX = 10e5; | ||
int a[MAX+10]; | ||
int n; | ||
ll k; | ||
|
||
ll calc(int p) { | ||
ll result = 0; | ||
|
||
for (int i = 1; i <= n-p+1; i++) | ||
result += a[p+i-1]/i; | ||
|
||
return result; | ||
} | ||
|
||
int main (void) { | ||
ios_base::sync_with_stdio(false); | ||
|
||
int T; | ||
scanf("%d", &T); | ||
|
||
while(T--) { | ||
scanf("%d %d", &n, &k); | ||
|
||
for(int i = 1; i <= n; i++) | ||
scanf("%d", a+i); | ||
|
||
ll v; | ||
int min_i = -1; | ||
|
||
for (int i = 1; i <= n; i++) { | ||
v = calc(i); | ||
|
||
if (k-v >= 0) { | ||
min_i = i; | ||
break; | ||
} | ||
} | ||
|
||
if (min_i == -1) min_i = n+1; | ||
|
||
printf("%d\n", min_i); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
|
83 changes: 83 additions & 0 deletions
83
code-chef/march-challenge-2019-div-2/cheating-on-queue/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
#define pb push_back | ||
#define eb emplace_back | ||
#define mk make_pair | ||
#define fi first | ||
#define se second | ||
|
||
typedef long long ll; | ||
typedef pair<int, int> ii; | ||
const int INF = 0x3f3f3f3f; | ||
const double PI = acos(-1.0); | ||
|
||
const int MAX = 10e5; | ||
struct as { | ||
int a, i; | ||
}; | ||
as a[MAX+10]; | ||
int idx[MAX+10]; | ||
int n; | ||
ll k; | ||
|
||
ll calc(int p) { | ||
ll result = 0; | ||
|
||
for (int i = 1; i <= n && result<=k; i++) { | ||
result += (a[i].i >= p ? a[i].a/(a[i].i-p+1) : 0); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
int comp(as a1, as a2) { | ||
return a1.a > a2.a; | ||
} | ||
|
||
int main (void) { | ||
ios_base::sync_with_stdio(false); | ||
|
||
int T; | ||
scanf("%d", &T); | ||
|
||
while(T--) { | ||
scanf("%d %d", &n, &k); | ||
|
||
for(int i = 1; i <= n; i++){ | ||
scanf("%d", &(a[i].a)); | ||
a[i].i = i; | ||
} | ||
|
||
sort(a+1, a+n+1, comp); | ||
|
||
ll v; | ||
int l = 1, r = n; | ||
int i = -1; | ||
|
||
while (l <= r) { | ||
int m = (l+r)/2; | ||
v = calc(m); | ||
|
||
if (k - v >= 0) { | ||
r = m-1; | ||
|
||
if (i == -1 || m < i) i = m; | ||
} else { | ||
v = calc(l); | ||
if (k-v >= 0) {i = l;break;} | ||
|
||
l = l+1; | ||
} | ||
} | ||
|
||
if (i == -1) i = n+1; | ||
|
||
printf("%d\n", i); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
|
68 changes: 68 additions & 0 deletions
68
code-chef/march-challenge-2019-div-2/cheating-on-queue/main2.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <stdio.h> | ||
#include <queue> | ||
|
||
using namespace std; | ||
|
||
const int MAX = 10e5; | ||
struct as { | ||
int a, i; | ||
}; | ||
as a[MAX+10]; | ||
int n; | ||
int k; | ||
int result; | ||
|
||
queue<int> update[MAX+10]; | ||
|
||
int calc(int p) { | ||
if (p > n) return p; | ||
|
||
while (!update[p].empty()) { | ||
int i = update[p].front(); | ||
result += ((i-p+1)>0 ? a[i].a/(i-p+1) : 0)- (a[i].i > 0 ? a[i].a/a[i].i : 0); | ||
a[i].i = (p+i-1); | ||
update[p].pop(); | ||
} | ||
|
||
if (result <= k) return p; | ||
else return calc(p+1); | ||
} | ||
|
||
void build() { | ||
int diff; | ||
int curr; | ||
for(int i = 1; i <= n; i++) { | ||
update[i+1].push(i); | ||
diff = -1; | ||
for (int j = i, it=i; j > 0; j--,it--) { | ||
curr = a[i].a / j; | ||
if (curr != diff) { | ||
update[it].push(i); | ||
diff = curr; | ||
} | ||
} | ||
} | ||
} | ||
|
||
int main (void) { | ||
int T; | ||
scanf("%d", &T); | ||
a[0].a = 0; | ||
a[0].i = 1; | ||
|
||
while(T--) { | ||
scanf("%d %d", &n, &k); | ||
result = 0; | ||
|
||
for(int i = 1; i <= n; i++){ | ||
scanf("%d", &(a[i].a)); | ||
a[i].i = 0; | ||
} | ||
|
||
build(); | ||
|
||
printf("%d\n", calc(1)); | ||
} | ||
|
||
return 0; | ||
} |
62 changes: 62 additions & 0 deletions
62
code-chef/march-challenge-2019-div-2/chef-and-a-beautiful-digit/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
#define pb push_back | ||
#define eb emplace_back | ||
#define mk make_pair | ||
#define fi first | ||
#define se second | ||
|
||
typedef long long ll; | ||
typedef pair<int, int> ii; | ||
const int INF = 0x3f3f3f3f; | ||
const double PI = acos(-1.0); | ||
|
||
ll d; | ||
|
||
char n[19]; | ||
|
||
int main (void) { | ||
ios_base::sync_with_stdio(false); | ||
|
||
int T; | ||
scanf("%d", &T); | ||
|
||
while(T--) { | ||
scanf("%s %lld", n, &d); | ||
|
||
int n_length = -1; | ||
|
||
while (n[++n_length] != '\0'); | ||
|
||
int i_min = -1; | ||
int n_count = 0; | ||
|
||
while (i_min < n_length-1) { | ||
i_min++; | ||
int i = i_min; | ||
char v_min = n[i]; | ||
|
||
while(n[i] != '\0') { | ||
if (n[i] < v_min) { | ||
v_min = n[i]; | ||
i_min = i; | ||
} | ||
i++; | ||
} | ||
|
||
if (v_min > ('0'+d)) break; | ||
printf("%c", v_min); | ||
n_count++; | ||
} | ||
|
||
while (n_count++ < n_length) | ||
printf("%d", d); | ||
|
||
printf("\n"); | ||
} | ||
return 0; | ||
} | ||
|
||
|
51 changes: 51 additions & 0 deletions
51
code-chef/march-challenge-2019-div-2/chef-and-number-game/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
#define pb push_back | ||
#define eb emplace_back | ||
#define mk make_pair | ||
#define fi first | ||
#define se second | ||
|
||
typedef long long ll; | ||
typedef pair<int, int> ii; | ||
const int INF = 0x3f3f3f3f; | ||
const double PI = acos(-1.0); | ||
|
||
int n; | ||
|
||
int a; | ||
int count_pos; | ||
int count_neg; | ||
|
||
int main (void) { | ||
ios_base::sync_with_stdio(false); | ||
|
||
int T; | ||
scanf("%d", &T); | ||
while(T--) { | ||
scanf("%d", &n); | ||
|
||
count_pos = 0; | ||
count_neg = 0; | ||
|
||
for(int i = 0; i <n; i++) { | ||
scanf("%d", &a); | ||
|
||
if (a < 0) count_neg++; | ||
else count_pos++; | ||
} | ||
|
||
if (count_neg == 0) count_neg = count_pos; | ||
if (count_pos == 0) count_pos = count_neg; | ||
|
||
if (count_neg < count_pos) swap(count_neg, count_pos); | ||
|
||
printf("%d %d\n", count_neg, count_pos); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
|
Oops, something went wrong.