2011/08/08

Codeforces Beta Round #80(Div.2) report

I submitted four, however I accepted two. It's bad score! Fortunately, my rank is still blue.

A: I listed answers with switch. This problem's inputs exist only 25 way. Submit and pretest passed at 0:05.

B: I was tired because I have some work before this contest. So, I can't concentrate this problem. I get a formula, and I submit, pretest passed at 0:25.

E: I think this problem is only calculating sum which is part of the sequence. However, I can't get good algorithm. I had many TLE(1:20).

D: I couldn't understand this. So, I anticipated the answer from samples. Surprisingly, I get pretest passed at 1:54 (of course, it's wrong!). This pretest is crude!

I get 1398,310/1093. Problems are here.

This round problems are difficult. Because Div.1 A=Div.2 B,1B=2C,1C=2D,1D=2E.

A

#include<stdio.h>

int main(void){
  int n,k;
  scanf("%d",&n);
  switch(n){
  case 11:
  case 12:
  case 13:
  case 14:
  case 15:
  case 16:
  case 17:
  case 18:
  case 19:
  case 21:
    k=4;
    break;
  case 20:
    k=15;
    break;
  default:
    k=0;
  }
  printf("%d\n",k);
  return 0;
}


B

#include<stdio.h>

int main(void){
  unsigned long long int n,sum=0,i,in;
  scanf("%I64u",&n);
  for(i=1;i<=n;i++){
    scanf("%I64u",&in);
    sum+=i*in-(i-1);
  }
  printf("%I64u\n",sum);
  return 0;
}



D(Wrong)

#include<stdio.h>
int main(void){
  unsigned long long int p,k,n,x;
  int flg;
  scanf("%I64u %I64u %I64u",&n,&k,&p);
  flg=n%2;
  if(flg==0 && 2*k>n) flg=2;
  while(p--){
    scanf("%I64u",&x);
    if(flg==0){
      if(x%2==0 && (n-x)/2+1<=k) putchar('X');
      else putchar('.');
    }else if(flg==1){
      if(x<=n-k) putchar('.');
      else putchar('X');
    }else{
      if(x%2==0) putchar('X');
      else if((n-x)/2+1<=k-n/2) putchar('X');
      else putchar('.');
    }
  }
  putchar('\n');
  return 0;
}


E(TLE)

#include<stdio.h>
#include<stdlib.h>

int main(void){
  unsigned int n,a,b,*w,p,i,j;
  unsigned long long int sum,allsum=0;
  scanf("%u",&n);
  w=(unsigned int *)calloc(n,sizeof(unsigned int));
  for(i=0;i<n;i++){
    scanf("%u",w+i);
    allsum+=*(w+i);
  }
  scanf("%u",&p);
  while(p--){
    scanf("%u %u",&a,&b);
    if(((n-a)/b+1)*2<=n){
      sum=0;
      for(i=a-1;i<n;i+=b) sum+=*(w+i);
    }else{
      sum=allsum;
      for(i=0;i<a-1;i++) sum-=*(w+i);
      for(i=a-1;i<n;i+=b) for(j=1;j<b;j++) sum-=*(w+i+j);
    }
    printf("%I64u\n",sum);
  }
  free(w);
  return 0;
}

0 件のコメント:

コメントを投稿