結果

問題 No.879 Range Mod 2 Query
ユーザー tnakao0123tnakao0123
提出日時 2019-09-09 08:24:13
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,192 bytes
コンパイル時間 811 ms
コンパイル使用メモリ 89,920 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-06-28 02:15:22
合計ジャッジ時間 6,468 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other WA * 1 TLE * 1 -- * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:51:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |   for (int i = 0; i < m; i++) scanf("%d", as + i);
      |                               ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - Many Slimes
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 18;
const int MAX_M = 1 << MAX_N;

/* typedef */

typedef pair<int,int> pii;
typedef multiset<int> msi;

/* global variables */

int as[MAX_M], vs[MAX_M];
msi xset;

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  int m = 1 << n;

  for (int i = 0; i < m; i++) scanf("%d", as + i);
  sort(as, as + m);

  xset.insert(m);

  for (int i = m - 1; i >= 0;) {
    int k = 1;
    while (k <= i && as[i] == as[i - k]) k++;
    i -= k;

    if (xset.size() < k) {
      puts("No");
      return 0;
    }

    msi::iterator mit = xset.end();
    for (int j = 0; j < k; j++) vs[j] = *(--mit);
    xset.erase(mit, xset.end());

    for (int j = 0; j < k; j++)
      for (int b = 1; b < vs[j]; b <<= 1) xset.insert(b);
  }

  puts("Yes");
  return 0;
}
0