Cod sursa(job #3191097)

Utilizator sad_carrotVisan Sebastian sad_carrot Data 8 ianuarie 2024 19:57:02
Problema Cc Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream f("cc.in");
ofstream g("cc.out");

int main() {
    int n, c, aux;
    f >> n;
    vector<vector<int>> costs(n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++) {
            f >> c;
            costs[i].push_back(c);
        }
    }
    vector<int> matching(n, 0);
    for(int i = 0; i < n; i++)
        matching[i] = i;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            if(i != j){
                //incercam sa schimba matching ai i -> matching[j] si j -> matching[i]
                if(costs[i][matching[i]] + costs[j][matching[j]] > costs[i][matching[j]] + costs[j][matching[i]]){
                    aux = matching[i];
                    matching[i] = matching[j];
                    matching[j] = aux;
                }
            }
    int s = 0;
    for(int i = 0; i < n; i++)
        s += costs[i][matching[i]];
    g << s;
    return 0;
}