src2020/4067_coach/coach.cpp

42 lines
1.1 KiB
C++
Raw Normal View History

2020-03-29 12:01:29 +08:00
#include <iostream>
2020-03-29 11:13:33 +08:00
using namespace std;
2020-03-29 12:01:29 +08:00
int main()
{
int k, n, a[11][21] = { 0 };
cin >> k >> n;
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j] ;
2020-03-29 11:13:33 +08:00
}
}
2020-03-29 12:01:29 +08:00
int c[21][21] = { 0 };
bool ce[21][21] = { 0 };
for (int i = 1; i <= n; i++) {
for (int j = i + 1;j<=n; j++) {
c[a[1][i]][0]++;
c[a[1][i]][c[i][0]] = a[1][j];
ce[a[1][i]][c[i][0]] = 1;
2020-03-29 11:13:33 +08:00
}
}
2020-03-29 12:01:29 +08:00
for (int i = 1; i <= k; i++) { //k
for (int e = 1; e <= n; e++) {
for (int j = 1; j <= c[a[i][e]][0]; j++) { //
if (ce[a[i][e]][j] == 1) {
c[a[i][e]][0]--;
ce[a[i][e]][j] = 0;
for (int w = e + 1; w <= n; w++) {
if (a[i][w] == c[a[i][e]][j]) {
c[a[i][e]][0]++;
ce[a[i][e]][j] = 1;
}
}
}
}
}
}
int ans=0;
for(int i=1;i<=n;i++){
ans+=c[i][0];
}
cout<<ans;
2020-03-29 11:13:33 +08:00
}