結果
| 問題 |
No.190 Dry Wet Moist
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-04 21:23:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 795 bytes |
| コンパイル時間 | 1,895 ms |
| コンパイル使用メモリ | 208,052 KB |
| 最終ジャッジ日時 | 2025-01-11 15:46:03 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:44:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
44 | int n; scanf("%d",&n); n*=2;
| ~~~~~^~~~~~~~~
main.cpp:46:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
46 | rep(i,n) scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int solve1(vector<int> a){
int n=a.size();
sort(a.rbegin(),a.rend());
int res=0,idx=n-1;
rep(i,n){
if(idx>i && a[i]+a[idx]<=0){
idx--;
}
if(idx>i && a[i]+a[idx]>0){
res++;
idx--;
}
}
return res;
}
int solve2(vector<int> a){
int n=a.size();
map<int,int> f;
rep(i,n) ++f[a[i]];
int res=0;
for(auto it=f.begin();it!=f.end();++it){
auto [x,c]=*it;
if(x>0) break;
if(x==0){
res+=c/2;
}
else if(f.count(-x)>0) {
res+=min(c,f[-x]);
}
}
return res;
}
int main(){
int n; scanf("%d",&n); n*=2;
vector<int> a(n);
rep(i,n) scanf("%d",&a[i]);
rep(i,n) a[i]*=-1;
printf("%d ",solve1(a));
rep(i,n) a[i]*=-1;
printf("%d %d\n",solve1(a),solve2(a));
return 0;
}