aleksey.pechenin's blog

By aleksey.pechenin, 13 years ago, In Russian

Hello guys, I've tried to solve problem 131B, but I got WA on 10 test.

the problem is appeared so easy, but probably I've made mistake in my calculations.

What's wrong here?

static void Main(string[] args)
    {

       Console.ReadLine();
       string[] s = Console.ReadLine().Split(' ');
       Dictionary<long,long> a = new Dictionary<long,long>();
       for (int i = 0; i<s.Length;i++){
          long key = long.Parse(s[i]);
          if (!a.ContainsKey(key)) {
             a[key] = 0;
          }
          a[key] ++;
       }

       long count = 0;
       foreach (long item in a.Keys) {
         if (item == 0) {
          count = count + (a[item]*(a[item]-1)/2); 
          continue;
         }
         if (item>0) {
           if (a.ContainsKey(-item)) {
              count = a[item] * a[-item];
           }
         }
       }
       Console.WriteLine(count);
    }        
}

}

  • Vote: I like it
  • -7
  • Vote: I do not like it

| Write comment?