Monday, March 31, 2014

Codeforces Round #239 (Div. 2), problem: (A) Line to Cashier solution

Codeforces Round #239 (Div. 2), problem: (A) Line to Cashier: http://codeforces.com/contest/408/problem/A

Codeforces Round #239 (Div. 2), problem: (A) Line to Cashier editorial: http://codeforces.com/blog/entry/11333

Codeforces Round #239 (Div. 2), problem: (A) Line to Cashier solution: 

#include <iostream>
#include <cstdio>
#include <climits>
using namespace std;

int main() {
    int n, k[105], m, cnt, min;
    min=INT_MAX;
    scanf("%d", &n);
    for(int i=0; i<n; i++) scanf("%d", &k[i]);
    for(int i=0; i<n; i++) {
        cnt=0;
        for(int j=0; j<k[i]; j++) {
            scanf("%d", &m);
            cnt+=m*5;
            cnt+=15;
        }
        if(cnt<min) min=cnt;
    }
    printf("%d", min);
    return 0;
}

Saturday, March 29, 2014

codechef March Challenge 2014 Walk solution

codechef March Challenge 2014 Walk: http://www.codechef.com/MARCH14/problems/WALK , http://www.codechef.com/problems/WALK

codechef March Challenge 2014 Walk editorial: http://discuss.codechef.com/questions/39939/walk-editorial

codechef March Challenge 2014 Walk solution: http://ideone.com/HuRk2m


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

int main() {
 int t, n, w, max, in, step;
 scanf("%d", &t);
 while(t--) {
  step=max=in=0;
  scanf("%d", &n);
  for(int i=0; i<n; i++) {
   scanf("%d", &w);
   if(w>step) step=max=w, in=i;
   step--;
  }
  printf("%d\n", max+in);
 }
 return 0;
}


codechef March Cook-Off 2014 Dividing Stamps solution

codechef March Cook-Off 2014 Dividing Stamps: http://www.codechef.com/COOK44/problems/DIVIDING , http://www.codechef.com/problems/DIVIDING

codechef March Cook-Off 2014 Dividing Stamps editorial: http://discuss.codechef.com/questions/40353/dividing-editorial

codechef March Cook-Off 2014 Dividing Stamps solution: http://ideone.com/HuRk2m


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

int main() {
 long long int n, a, cnt;
 cnt=0;
 scanf("%lld", &n);
 for(int i=0; i<n; i++) scanf("%lld", &a), cnt+=a;
 if(n*(n+1)/2==cnt) printf("YES\n");
 else printf("NO\n");
 return 0;
}

Codeforces Round #237 (Div. 2), problem: (A) Valera and X solution

Codeforces Round #237 (Div. 2), problem: (A) Valera and X: http://codeforces.com/contest/404/problem/A

Codeforces Round #237 (Div. 2), problem: (A) Valera and X editorial: http://codeforces.com/blog/entry/11095

Codeforces Round #237 (Div. 2), problem: (A) Valera and X solution: http://ideone.com/fq6RN9


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

int main() {
    int n, flag;
    char s[305][305], diag, other;
    flag=0;
    scanf("%d", &n);
    for(int i=0; i<n; i++) scanf("%s\n", s[i]);
    diag=s[0][0];
    other=s[0][1];
    if(diag==other) flag=1;
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            if(i==j || i+j==n-1) {
                if(s[i][j]!=diag) {
                    flag=1;
                    break;
                }
            } 
            else {
                if(s[i][j]!=other) {
                    flag=1;
                    break;
                }
            }
        }
        if(flag) break;
    }
    if(flag) printf("NO");
    else printf("YES");
    return 0;
}

Saturday, March 22, 2014

Codeforces Round #238 (Div. 2), problem: (B) Domino Effect solution

Codeforces Round #238 (Div. 2), problem: (B) Domino Effect: http://codeforces.com/contest/405/problem/B

Codeforces Round #238 (Div. 2), problem: (B) Domino Effect solution: 

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

int main() {
    int n, r, l, ans, cnt;
    ans=cnt=r=l=0;
    char s[3005];
    scanf("%d", &n);
    scanf("%s", s);
    for(int i=0; i<n; i++) {
        if(s[i]=='.' && r==0) cnt++;
        if(s[i]=='L') {
            cnt=0;
            r=0;
        }
        if(s[i]=='R') {
            ans+=cnt;
            cnt=0;
            r=1;
        }
    }
    if(cnt>0) ans+=cnt, cnt=0;
    r=l=0;
    for(int i=0; i<n; i++) {
        if(s[i]=='R') r=1;
        if(s[i]=='.' && r==1) cnt++;
        if(s[i]=='L') {
            if(cnt%2==1) ans++;
            cnt=0;
            r=0;
        }
    }
    printf("%d", ans);
    return 0;
}

Codeforces Round #238 (Div. 2), problem: (A) Gravity Flip solution

Codeforces Round #238 (Div. 2), problem: (A) Gravity Flip: http://codeforces.com/contest/405/problem/A

Codeforces Round #238 (Div. 2), problem: (A) Gravity Flip solution: 

#include <iostream>
#include <stdio.h>      /* printf */
#include <stdlib.h>     /* qsort */

int n, a[105];

int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}

int main ()
{
    scanf("%d", &n);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    qsort (a, n, sizeof(int), compare);
    for(int i=0; i<n; i++) printf("%d ", a[i]);
    return 0;
}

Thursday, March 20, 2014

Codeforces Round #105 (Div. 2), problem: (A) Insomnia cure solution

Codeforces Round #105 (Div. 2), problem: (A) Insomnia cure: http://codeforces.com/problemset/problem/148/A

Codeforces Round #105 (Div. 2), problem: (A) Insomnia cure solution: http://ideone.com/8QDphs

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
    int k, l, m, n, d, a[100005], cnt;
    memset(a, 0, sizeof(a));
    cnt=0;
    scanf("%d%d%d%d%d", &k, &l, &m, &n, &d);
    for(int i=k-1; i<d; i+=k) a[i]++;
    for(int i=l-1; i<d; i+=l) a[i]++;
    for(int i=m-1; i<d; i+=m) a[i]++;
    for(int i=n-1; i<d; i+=n) a[i]++;
    for(int i=0; i<d; i++) if(a[i]) cnt++;
    printf("%d", cnt);
    return 0;
}