LeetCode Weekly Contest 206 2問目 - Count Unhappy Friends [1583]

Source

LeetCode Weekly Contest 206
問題文

問題概要

省略

解法

省略

cLayversion 20200913-1)のコード

C++に変換後のコードはこちら

#define main dummy_main
{}
#undef main

int op[501], cnt[501];
int bef[501][501];

class Solution {
public:
  int unhappyFriends(int n, vector<vector<int>>& preferences, vector<vector<int>>& pairs) {
    for(vector<int> d : pairs){
      op[d[0]] = d[1];
      op[d[1]] = d[0];
    }

    rep(i,n) rep(j,n) bef[i][j] = 0;
    rep(i,n) rep(j,n){
      if(preferences[i][j] == op[i]) break;
      bef[i][preferences[i][j]] = 1;
    }

    rep(i,n) cnt[i] = 0;
    rep(i,n) rep(j,i+1,n) if(bef[i][j] && bef[j][i]) cnt[i] = cnt[j] = 1;

    return sum(cnt(n));
  }
};

Current time: 2024年04月26日03時53分32秒
Last modified: 2020年09月13日13時49分31秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る

Logged in as: unknown user (not login)

ログイン: