結果

問題 No.1773 Love Triangle
ユーザー 👑 NachiaNachia
提出日時 2021-12-12 02:19:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 3,308 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 85,300 KB
実行使用メモリ 5,416 KB
最終ジャッジ日時 2023-09-27 16:44:43
合計ジャッジ時間 10,439 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 62 ms
4,648 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 37 ms
4,376 KB
testcase_25 AC 27 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 47 ms
4,376 KB
testcase_31 AC 49 ms
4,380 KB
testcase_32 AC 48 ms
4,636 KB
testcase_33 AC 15 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 AC 10 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 83 ms
5,176 KB
testcase_39 AC 84 ms
5,164 KB
testcase_40 AC 85 ms
5,172 KB
testcase_41 AC 88 ms
5,336 KB
testcase_42 AC 88 ms
5,120 KB
testcase_43 AC 85 ms
5,324 KB
testcase_44 AC 86 ms
5,112 KB
testcase_45 AC 84 ms
5,240 KB
testcase_46 AC 88 ms
5,164 KB
testcase_47 AC 85 ms
5,240 KB
testcase_48 AC 88 ms
5,172 KB
testcase_49 AC 88 ms
5,100 KB
testcase_50 AC 86 ms
5,112 KB
testcase_51 AC 87 ms
5,236 KB
testcase_52 AC 84 ms
5,164 KB
testcase_53 AC 86 ms
5,168 KB
testcase_54 AC 84 ms
5,116 KB
testcase_55 AC 87 ms
5,108 KB
testcase_56 AC 84 ms
5,240 KB
testcase_57 AC 85 ms
5,240 KB
testcase_58 AC 89 ms
5,188 KB
testcase_59 AC 88 ms
5,112 KB
testcase_60 AC 88 ms
5,108 KB
testcase_61 AC 89 ms
5,160 KB
testcase_62 AC 88 ms
5,168 KB
testcase_63 AC 88 ms
5,184 KB
testcase_64 AC 88 ms
5,112 KB
testcase_65 AC 89 ms
5,232 KB
testcase_66 AC 88 ms
5,108 KB
testcase_67 AC 89 ms
5,168 KB
testcase_68 AC 89 ms
5,116 KB
testcase_69 AC 89 ms
5,416 KB
testcase_70 AC 89 ms
5,120 KB
testcase_71 AC 90 ms
5,184 KB
testcase_72 AC 88 ms
5,124 KB
testcase_73 AC 89 ms
5,236 KB
testcase_74 AC 89 ms
5,100 KB
testcase_75 AC 89 ms
5,108 KB
testcase_76 AC 88 ms
5,232 KB
testcase_77 AC 88 ms
5,124 KB
testcase_78 AC 1 ms
4,380 KB
testcase_79 AC 5 ms
4,980 KB
testcase_80 AC 5 ms
5,116 KB
testcase_81 AC 88 ms
5,116 KB
testcase_82 AC 89 ms
5,164 KB
testcase_83 AC 24 ms
4,500 KB
testcase_84 AC 40 ms
4,380 KB
testcase_85 AC 75 ms
4,976 KB
testcase_86 AC 22 ms
4,376 KB
testcase_87 AC 46 ms
4,448 KB
testcase_88 AC 42 ms
5,064 KB
testcase_89 AC 34 ms
4,380 KB
testcase_90 AC 85 ms
5,244 KB
testcase_91 AC 58 ms
4,588 KB
testcase_92 AC 18 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;


#include <vector>
#include <cassert>
#include <atcoder/modint>


template<class Elem, atcoder::internal::is_static_modint_t<Elem>* = nullptr>
struct modulo_matrix{
private:
    using m32 = Elem;
public:
    int h;
    int w;
    std::vector<m32> elems;
    
    modulo_matrix(int new_h, int new_w){ h = new_h; w = new_w; elems.assign(h * w, 0); }
    modulo_matrix(const modulo_matrix&) = default;
    typename std::vector<m32>::iterator operator[](int y){ return elems.begin() + (y * w); }
    typename std::vector<m32>::const_iterator operator[](int y) const { return elems.begin() + (y * w); }
    static modulo_matrix identity(int idx){ auto res = modulo_matrix(idx, idx); for(int i = 0; i < idx; i++) res[i][i] = 1; return res; }
    modulo_matrix operator*(const modulo_matrix& r) const {
        assert(w == r.h);
        auto res = modulo_matrix(h, r.w);
        for (int i=0; i<h; i++) for (int j=0; j<w; j++) for (int k=0; k<r.w; k++) res[i][k] += (*this)[i][j] * r[j][k];
        return res;
    }
    m32 det() const {
        assert(h == w);
        modulo_matrix g = *this;
        m32 ans = 1;
        for (int i=0; i<h; i++) {
            int tg = -1;
            for (int j=i; j<h; j++) { if (g[j][i] != 0) tg = j; }
            if (tg == -1) return 0;
            if (tg != i) ans = -ans;
            for (int j=0; j<h; j++) std::swap(g[i][j], g[tg][j]); tg = i;
            ans *= g[i][i];
            m32 const_coeff = g[i][i].inv();
            for (int j=0; j<h; j++) g[i][j] *= const_coeff;
            for (int j=i+1; j<h; j++) for(int k=h-1; k>=i; k--) g[j][k] -= g[j][i] * g[i][k];
        }
        return ans;
    }
    int rank() const {
        modulo_matrix g = *this;
        int y = 0;
        for (int i=0; i<w; i++) {
            if(y == h) break;
            int tg = -1;
            for (int j=y; j<h; j++) { if (g[j][i] != 0){ tg = j; break; } }
            if (tg == -1) continue;
            for (int j=i; j<w; j++) std::swap(g[y][j], g[tg][j]); tg = y;
            m32 const_coeff = g[y][i].inv();
            for (int j=i; j<w; j++) g[y][j] *= const_coeff;
            for (int j=y+1; j<w; j++) for(int k=w-1; k>y; k--) g[j][k] -= g[j][i] * g[y][k];
            y++;
        }
        return y;
    }
};

#include <vector>

using namespace std;

using m32 = atcoder::static_modint<998244353>;
using Matrix = modulo_matrix<m32>;

int main() {
    int N,M; cin >> N >> M;

    vector<vector<pair<int,m32>>> A(M);
    vector<vector<pair<int,m32>>> B(M);
    for(int i=0; i<M; i++){
        int u,v,w; cin >> u >> v >> w; u--; v--; w--;
        A[i].push_back(make_pair(u, m32(1)));
        A[i].push_back(make_pair(v, m32(-1)));
        B[i].push_back(make_pair(v, m32(1)));
        B[i].push_back(make_pair(w, m32(-1)));
    }

    modulo_matrix<m32> G(N,N);
    m32 rng_r = 10000;
    m32 rng = 1;
    for(int i=0; i<M; i++){
        rng *= rng_r;
        for(auto [y,vy] : A[i]) for(auto [x,vx] : B[i]) G[y][x] += rng * vy * vx;
        for(auto [y,vy] : A[i]) for(auto [x,vx] : B[i]) G[x][y] -= rng * vy * vx;
    }

    int ans = G.rank() / 2;
    cout << ans << endl;
    return 0;
}

0