結果
| 問題 | No.911 ラッキーソート |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2019-10-21 01:14:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,623 bytes |
| 記録 | |
| コンパイル時間 | 848 ms |
| コンパイル使用メモリ | 83,872 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-02 17:38:27 |
| 合計ジャッジ時間 | 4,110 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 35 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:55:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
55 | scanf("%d%lld%lld", &n, &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:57:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
57 | for (int i = 0; i < n; i++) scanf("%lld", as + i);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 911.cc: No.911 ラッキーソート - yukicoder
*/
#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 = 200000;
const int BN = 61;
/* typedef */
typedef long long ll;
/* global variables */
ll as[MAX_N], es[MAX_N], dp[BN + 1];
int ds[BN];
/* subroutines */
ll count(ll a) {
ll c = 0;
for (int k = BN - 1; k >= 0; k--)
if ((a >> k) & 1) c += dp[k];
return c;
}
/* main */
int main() {
int n;
ll l, r;
scanf("%d%lld%lld", &n, &l, &r);
for (int i = 0; i < n; i++) scanf("%lld", as + i);
for (int k = BN - 1; k >= 0; k--) {
ll bk = 1LL << k;
ll pe0 = es[0] | (as[0] & bk), pe1 = pe0 ^ bk;
bool ok0 = true, ok1 = true;
for (int i = 1; i < n; i++) {
ll ei0 = es[i] | (as[i] & bk), ei1 = ei0 ^ bk;
if (pe0 > ei0) ok0 = false;
if (pe1 > ei1) ok1 = false;
pe0 = ei0, pe1 = ei1;
}
int di = 0;
if (ok0) di++;
if (ok1) di++;
if (di == 0) {
puts("0");
return 0;
}
ds[k] = di;
for (int i = 0; i < n; i++) {
es[i] |= (as[i] & bk);
if (! ok0) es[i] ^= bk;
}
}
dp[0] = 1;
for (int k = 0; k < BN; k++) dp[k + 1] = dp[k] * ds[k];
ll cl = count(l), cr = count(r + 1);
//printf("cl=%lld, cr=%lld\n", cl, cr);
printf("%lld\n", cr - cl);
return 0;
}
tnakao0123