結果

問題 No.2092 Conjugation
ユーザー qqspeed20015
提出日時 2022-10-08 23:24:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 853 bytes
コンパイル時間 2,128 ms
コンパイル使用メモリ 199,940 KB
最終ジャッジ日時 2025-02-08 00:36:58
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         scanf("%d", &num);
      |         ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int countGreater(vector <int> &arr, int n, int k)
{
    int l = 0, r = n - 1;
    int leftGreater = n;
    while (l <= r) {
        int m = l + (r - l) / 2;
        if (arr[m] > k) {
            leftGreater = m;
            r = m - 1;
        }
        else
            l = m + 1;
    }
    return (n - leftGreater);
}

int main() {
    int n, num;
    scanf("%d", &n);
    vector <int> listNum, res;
    for (int i = 0; i < n; i++) {
        scanf("%d", &num);
        listNum.push_back(num);
    }
    vector <int> tmp = listNum;
    sort(tmp.begin(), tmp.end());
    for (int i = 1; i <= listNum[0]; i++)
        res.push_back(countGreater(tmp, n, i - 1));
    for (int i = 0; i < listNum[0]; i++) {
        cout << res[i];
        if (i != listNum[0] - 1)
            cout << " ";
    }
    return 0;
}
0