LeetCode Weekly Contest 182 2問目 - Count Number of Teams [1395]

Source

LeetCode Weekly Contest 182
問題文

問題概要

省略

解法

省略

cLayversion 20200325-1)のコード

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

#define main dummy_main
{}
#undef main

class Solution {
public:
  int numTeams(vector<int>& A) {
    int N = A.size(), c1, c2, res = 0;
    rep(i,N){
      c1 = c2 = 0;
      rep(j,i) if(A[j] < A[i]) c1++;
      rep(k,i+1,N) if(A[k] > A[i]) c2++;
      res += c1 * c2 + (i-c1) * (N-i-1-c2);
    }
    return res;
  }
};

Current time: 2024年03月30日00時02分32秒
Last modified: 2020年03月30日02時54分33秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る

Logged in as: unknown user (not login)

ログイン: