QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#144928 | #2771. Need for Speed | PetroTarnavskyi# | WA | 1ms | 3540kb | C++17 | 2.2kb | 2023-08-21 20:01:38 | 2023-08-21 20:01:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = int(a); i < int(b); i++)
#define RFOR(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long double db;
const int MAX = 300;
VI g[MAX];
int mt[MAX];
int P[MAX];
int U[MAX];
int iter;
bool kun(int x)
{
if (U[x] == iter) return false;
U[x] = iter;
FOR (i, 0, SZ(g[x]))
{
int to = g[x][i];
if (mt[to] == -1)
{
mt[to] = x;
P[x] = to;
return true;
}
}
FOR (i, 0, SZ(g[x]))
{
int to = g[x][i];
if (kun(mt[to]))
{
mt[to] = x;
P[x] = to;
return true;
}
}
return false;
}
int doKun(int n)
{
FILL(mt, -1);
FILL(P, -1);
FILL(U, -1);
int res = 0;
iter = 0;
while(true)
{
iter++;
bool ok = false;
FOR (i, 0, n)
{
if (P[i] == -1)
{
if(kun(i))
{
ok = true;
res++;
}
}
}
if (!ok) break;
}
return res;
}
int a[MAX][MAX];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
set<int> s;
LL sum = 0;
FOR (i, 0, n)
{
FOR (j, 0, m)
{
cin >> a[i][j];
sum += a[i][j];
if (a[i][j])
{
s.insert(a[i][j]);
sum--;
}
}
}
vector<bool> ur(n, false);
vector<bool> uc(m, false);
VI v(ALL(s));
reverse(ALL(v));
for (LL val : v)
{
VI rows, cols;
FOR (i, 0, n)
{
FOR (j, 0, m)
{
if (!ur[i] && a[i][j] == val)
{
ur[i] = 1;
rows.PB(i);
}
if (!uc[j] && a[i][j] == val)
{
uc[j] = 1;
cols.PB(j);
}
}
}
FOR (i, 0, SZ(rows))
{
FOR (j, 0, SZ(cols))
{
int r = rows[i];
int c = cols[j];
if (a[r][c] != 0)
{
g[i].PB(SZ(rows) + j);
g[SZ(rows) + j].PB(i);
}
}
}
int x = doKun(SZ(rows) + SZ(cols));
FOR (i, 0, SZ(rows) + SZ(cols)) g[i].clear();
sum -= (val - 1) * (SZ(rows) + SZ(cols) - x / 2);
}
cout << sum << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3540kb
input:
3 5 4 -1 4 0 10 3
output:
0
result:
wrong answer 1st numbers differ - expected: '3.0000000', found: '0.0000000', error = '1.0000000'