432B - Football Kit - CodeForces Solution


brute force greedy implementation *1200

Please click on ads to support us..

Python Code:

n = int(input())
x = list()
y = list()

for i in range(n):
    a, b = list(map(int, input().split()))
    x.append(a)
    y.append(b)

ans_home = list()
ans_away = list()
cnt = [0]*(10**6)

for i in range(n):
    cnt[x[i]]+=1

for i in range(n):
    ans_home.append(n-1+cnt[y[i]])
    ans_away.append((2*(n-1))-ans_home[i])
    print(ans_home[i], ans_away[i])

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    int n,t;
    cin>>n;
    int h[200000]={0},a[n+1],i,p,l,s,d;
    for(i=1;i<=n;i++)
    {
        cin>>p>>a[i];
        h[p]++;
    }
    for(i=1;i<=n;i++)
    {
        s=n-1;
        d=h[a[i]];
        if(a[i]==0)
        d=0;
        cout<<s+d<< " "<<s-d<<endl;
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House
67A - Partial Teacher
116A - Tram
1472B - Fair Division
1281C - Cut and Paste
141A - Amusing Joke
112A - Petya and Strings
677A - Vanya and Fence
1621A - Stable Arrangement of Rooks
472A - Design Tutorial Learn from Math
1368A - C+=
450A - Jzzhu and Children
546A - Soldier and Bananas
32B - Borze
1651B - Prove Him Wrong
381A - Sereja and Dima
41A - Translation
1559A - Mocha and Math
832A - Sasha and Sticks
292B - Network Topology
1339A - Filling Diamonds
910A - The Way to Home
617A - Elephant
48A - Rock-paper-scissors
294A - Shaass and Oskols