# LCDR2022 - Editorial

LongCode Dribble - a 24 hours long coding contest hosted for students of GLA University.

LCDR01

``````#include <iostream>
using namespace std;

int main() {
string s1,s2,s3;
int t1=0,t2=0,t3=0;
cin>>s1>>s2>>s3;
if(s1=="GE") t1++;
else t2++;
if(s2=="VLT") t2++;
else t3++;
if(s3=="EG") t3++;
else t1++;
if(t1==t2 && t2==t3) cout<<"DRAW"<<endl;
else{
int n = t1>t2?t2:t1;
n = n>t3?t3:n;
if(n==t1) cout<<"GE"<<endl;
else if(n==t2) cout<<"VLT"<<endl;
else cout<<"EG"<<endl;
}
return 0;
}
``````

LCDR02

``````#include <algorithm>
#include <iostream>
#include <type_traits>
using namespace std;

#define REP1(i, n) for (remove_cv<remove_reference<decltype(n)>::type>::type i = 1; i <= (n); i++)

int main()
{
long cc, l, a, n, d;
cin >> cc;
while (cc--) {
cin >> l >> a >> n >> d;
if (d > a)
else if (d == 1)
cout << l*a << endl;
else {
long s = -1;
REP1(i, (n-1)/(d-1)) {
long x = n-1-(d-1)*i; // extra frequency of A
if (x+a*i < l) continue;
long c = (l-x)/i; // number of items >= i
s = max(s, a*x + (2*a-c+1)*c/2*i + (a-c)*((l-x)%i));
}
if (s < 0)
else
cout << s << endl;
}
}
}
``````

LCDR03

``````#include <iostream>

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
{
long long n, k;
cin >> n >> k;
if (k <= (n + 1) / 2)
{
cout << k * 2 - 1 << endl;
}
else
{
cout << (k - (n + 1) / 2) * 2 << endl;
}

}
}
``````

LCDR04

``````#include<bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int arr[n];
for (int i = 0; i < n; ++i)
{
cin>>arr[i];
}

long long int count = 0;
int min[n];
min[0] = arr[0];
for(int i=1;i<n;i++){
if(arr[i] < min[i-1]){
min[i] = arr[i];
}else{
min[i] = min[i-1];
}
}
for(int i = n-1;i>=0;i--){
count += min[i];
}
cout<<count<<endl;
}
return 0;
}
``````

LCDR05

``````#include<bits/stdc++.h>
using namespace std;
long long int printPrimeFactors(long long int n) {
long long int count=0;
while (n%2 == 0){
n = n/2;
count++;
}
for (int i = 3; i <= sqrt(n); i = i+2){
while (n%i == 0){
count++;
n = n/i;
}
}
if (n > 2)
count++;
return count;
}
int main() {
int t;
cin>>t;
while(t--)
{
long long int num;
cin>>num;
long long int ans=printPrimeFactors(num);
if(ans>2)
cout<<"Yes\n";
else
cout<<"No\n";
}
}
``````

LCDR06

``````#include <iostream>

int main(){

long t; scanf("%ld", &t);
while(t--){
long n; std::cin >> n;
std::string s; std::cin >> s;
long z(0), a(0);
for(long p = 0; p < n; p++){
if(s[p] == '0'){++z;}
else{break;}
}
for(long p = n - 1; p >= 0; p--){
if(s[p] == '1'){++a;}
else{break;}
}

z += (a + z < n);
for(long p = 0; p < z; p++){std::cout << '0';}
for(long p = 0; p < a; p++){std::cout << '1';}
std::cout << std::endl;
}

return 0;
}
``````

LCDR07

``````#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
char s[maxn];
int main() {
int t;
cin>>t;
while(t--)
{
//string s;
int x,cnt=0;
cin>>s+1;
cin>>x;
int n=strlen(s+1);
for(int i=1;i<=n;i++){
int temp=i;
cnt=0;
for(int j=i+1;j<=n;j++){
if(s[j]>s[temp]&&x>=j-i){
temp=j;
cnt=j-i;
}
}
if(s[temp]==s[i])continue;
for(int k=temp;k>i;k--){
swap(s[k],s[k-1]);
}
x-=cnt;
}
cout<<s+1<<endl;
}
}
``````

LCDR08

`````` #include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

const int LMAX = 100005;

double a[10];
char *p, s[LMAX];

double e(), f();

int main() {
cin.sync_with_stdio(false);

int n;
cin >> n;

for (int i = 1; i <= n; i++)
cin >> a[i];

cin >> s;
p = s;
cout << fixed << setprecision(10) << e() << '\n';

return 0;
}

double e() {
double r = f();

while (*p == '-' || *p == '|') {
if (*p == '-') {
p++;
r += f();
} else {
p++;
double r2 = f();
r = r * r2 / (r + r2);
}
}

return r;
}

double f() {
double r = 0;

if (*p == '(') {
p++;
r = e();
p++;
return r;
}

p++;
r = a[*p - '0'];
p++;

return r;
}
``````