Coder-Strike 2014 - Round 2 B. Spyke Chatting

題目:ios

B. Spyke Chattingide

time limit per testthis

1 secondidea

memory limit per testspa

256 megabytescode

inputthree

standard inputip

outputci

standard outputelement

The R2 company has n employees working for it. The work involves constant exchange of ideas, sharing the stories of success and upcoming challenging. For that, R2 uses a famous instant messaging program Spyke.

R2 has m Spyke chats just to discuss all sorts of issues. In each chat, some group of employees exchanges messages daily. An employee can simultaneously talk in multiple chats. If some employee is in the k-th chat, he can write messages to this chat and receive notifications about messages from this chat. If an employee writes a message in the chat, all other participants of the chat receive a message notification.

The R2 company is conducting an audit. Now the specialists study effective communication between the employees. For this purpose, they have a chat log and the description of chat structure. You, as one of audit specialists, are commissioned to write a program that will use this data to determine the total number of message notifications received by each employee.

Input

The first line contains three space-separated integers nm and k (2 ≤ n ≤ 2·104; 1 ≤ m ≤ 10; 1 ≤ k ≤ 2·105) — the number of the employees, the number of chats and the number of events in the log, correspondingly.

Next n lines contain matrix a of size n × m, consisting of numbers zero and one. The element of this matrix, recorded in the j-th column of the i-th line, (let's denote it as aij) equals 1, if the i-th employee is the participant of the j-th chat, otherwise the element equals 0. Assume that the employees are numbered from 1 to n and the chats are numbered from 1 to m.

Next k lines contain the description of the log events. The i-th line contains two space-separated integers xi and yi (1 ≤ xi ≤ n; 1 ≤ yi ≤ m) which mean that the employee number xi sent one message to chat number yi. It is guaranteed that employee number xi is a participant of chat yi. It is guaranteed that each chat contains at least two employees.

Output

Print in the single line n space-separated integers, where the i-th integer shows the number of message notifications the i-th employee receives.

Sample test(s)

input

3 4 5
1 1 1 1
1 0 1 1
1 1 0 0
1 1
3 1
1 3
2 4
3 2

output

3 3 1

input

4 3 4
0 1 1
1 0 1
1 1 1
0 0 0
1 2
2 1
3 1
1 3

output

0 2 3 0


代碼:

#include <iostream>


#define MAXN 25000
#define MAXM 15
#define MAXK 250000

using namespace std;

int ans[MAXN], record[MAXN];
int chatTable[MAXM][MAXN];

int x, y;
int n , m , k;
int i, j;

int main()
{
    cin >> n >> m >> k;
    for(i = 1; i <= n ; i++)
        for(j = 1; j <= m; j++)
            cin >> chatTable[j][i];

    for(j = 1; j <= k; j++){
        cin >> x >> y;
        ans[x]--;
        record[y]++;
    }
    for(i = 1; i <= n ; i++)
        for(j = 1; j <= m; j++)
            if(chatTable[j][i])
                ans[i] += record[j];

    for(i = 1; i < n; i++)
        cout << ans[i] << " ";
    cout << ans[i] << "\n";
    return 0;
}

分析:直接模擬會超時,將問題轉換爲先收集各個chat中的回話總數,而後分配給各個用戶

相關文章
相關標籤/搜索