提出 #34046397
ソースコード 拡げる
#include<bits/stdc++.h>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define m_p make_pair
#define pb push_back
#define fi first
#define se second
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
using namespace std;
const int N=200005;
int n;
int p[N];
vector<int>ans;
int main(){
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(0);
cin>>n;n*=2;
forn(i,1,n)cin>>p[i];
if(n==2){
if(p[1]>p[2]){
cout<<"1\n";
cout<<1<<"\n";return 0;
}
else{
cout<<"0\n";
return 0;
}
}
if(p[1]>p[2]){
ans.pb(1);swap(p[1],p[2]);
}
for(int i=3;i<=n;i++){
if(i&1){
if(p[i]>p[i-1]){
ans.pb(i-1);
swap(p[i],p[i-1]);
}
}
else{
if(p[i]<p[i-1]){
ans.pb(i-1);
swap(p[i],p[i-1]);
}
}
}
if(ans.size()>n/2){
cout<<n/2<<"\n";
for(int i=1;i<=n;i+=2)cout<<i<<" ";
return 0;
}
else{
cout<<ans.size()<<"\n";
for(auto x:ans)cout<<x<<" ";
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | A - Make it Zigzag |
| ユーザ | yangchenhao |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 400 |
| コード長 | 1127 Byte |
| 結果 | AC |
| 実行時間 | 32 ms |
| メモリ | 5004 KiB |
コンパイルエラー
./Main.cpp: In function ‘int main()’:
./Main.cpp:49:15: warning: comparison of integer expressions of different signedness: ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
49 | if(ans.size()>n/2){
| ~~~~~~~~~~^~~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 400 / 400 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00-sample-001.txt, 00-sample-002.txt |
| All | 00-sample-001.txt, 00-sample-002.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00-sample-001.txt | AC | 5 ms | 3580 KiB |
| 00-sample-002.txt | AC | 2 ms | 3508 KiB |
| 01-001.txt | AC | 2 ms | 3540 KiB |
| 01-002.txt | AC | 2 ms | 3528 KiB |
| 01-003.txt | AC | 3 ms | 3476 KiB |
| 01-004.txt | AC | 2 ms | 3576 KiB |
| 01-005.txt | AC | 3 ms | 3572 KiB |
| 01-006.txt | AC | 2 ms | 3464 KiB |
| 01-007.txt | AC | 25 ms | 4288 KiB |
| 01-008.txt | AC | 13 ms | 3952 KiB |
| 01-009.txt | AC | 28 ms | 4428 KiB |
| 01-010.txt | AC | 11 ms | 3788 KiB |
| 01-011.txt | AC | 23 ms | 4256 KiB |
| 01-012.txt | AC | 32 ms | 4576 KiB |
| 01-013.txt | AC | 31 ms | 4540 KiB |
| 01-014.txt | AC | 29 ms | 4540 KiB |
| 01-015.txt | AC | 31 ms | 4512 KiB |
| 01-016.txt | AC | 28 ms | 4512 KiB |
| 01-017.txt | AC | 32 ms | 4480 KiB |
| 01-018.txt | AC | 31 ms | 4540 KiB |
| 01-019.txt | AC | 29 ms | 4556 KiB |
| 01-020.txt | AC | 27 ms | 4288 KiB |
| 01-021.txt | AC | 32 ms | 5004 KiB |