結果
| 問題 |
No.2276 I Want AC
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-21 21:53:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 1,160 bytes |
| コンパイル時間 | 812 ms |
| コンパイル使用メモリ | 86,308 KB |
| 最終ジャッジ日時 | 2025-02-12 11:34:08 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 56 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | scanf("%d %s", &n, ib);
| ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;
bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
class mypcmp {
public:
bool operator()(const int& a, const int& b) {
return a<b;
}
};
char ib[200004];
int cx[200004];
int ax[200004];
int main() {
int n, i;
LL b, c, r, t, c1, c2, x;
scanf("%d %s", &n, ib);
b=0; c=0;
for (i=n-1; i>=0; i--) {
if (ib[i]=='C') c++;
cx[i]=c;
}
c=0; for (i=0; i<n; i++) {
if (ib[i]=='A') c++;
ax[i]=c;
}
for (i=0; i<n; i++) if (ib[i]=='A') b+=cx[i];
r=b;
c2=0;
for (i=0; i<n; i++) if (ib[i]=='?') { r+=ax[i]; c2++; }
c1=0;
x=r;
for (i=0; i<n; i++) {
if (ib[i]=='?') {
c2--; c1++;
// <-i 'A'
x-=ax[i];
x+=cx[i];
t=x+c1*c2;
r = max(r, t);
}
}
printf("%lld\n", r);
return 0;
}