Submission #59914354
Source Code Expand
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define REP_(I,N) for (int I=0,END=(N);I<END;I++)
#define rREP_(I,N) for (int I=(N)-1;I>=0;I--)
#define rep_(I,S,N) for (int I=(S),END=(N);I<END;I++)
#define rrep_(I,S,N) for (int I=(N)-1,START=(S);I>=START;I--)
#define FOR_(I,S,N) for (int I=(S),END=(N);I<=END;I++)
#define rFOR_(I,S,N) for (int I=(N),START=(S);I>=START;I--)
#define DEBUG
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define deputs(str) fprintf(stderr, "%s\n",str)
#else
#define debug(...)
#define deputs(str)
#endif // DEBUG
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef long long LL;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fll;
const LL maxn=2e6+7;
const double pi=acos(-1.0);
const double eps=1e-10;
template<typename T>inline void pr2(T x,int k=64) {REP_(i,k) printf("%d",(x>>i)&1); putchar(' ');}
template<typename T>inline void max_(T &A,T B) {(A<B) &&(A=B);}
template<typename T>inline void min_(T &A,T B) {(A>B) &&(A=B);}
inline ll fastgcd(ll a, ll b) { // __gcd()
if (!b) return a;
ll az=__builtin_ctzll(a),bz=__builtin_ctzll(b),z=min(az,bz),diff; b>>=bz;
while (a) {
a>>=az, diff=b-a, az=__builtin_ctzll(diff);
(b>a)&&(b=a), a=abs(diff);
}
return b<<z;
}
int startTime;
void startTimer() {startTime=clock();}
void printTimer() {debug("/--- Time: %ld milliseconds ---/\n",clock()-startTime);}
typedef array<int,5> ar5;
typedef array<int,4> ar4;
typedef array<int,3> ar3;
std::mt19937 rng(time(0));
std::mt19937_64 rng64(time(0));
vector<pii> direction4 = {{-1,0},{0,-1},{0,1},{1,0}};
vector<pii> direction8 = {{-1,-1},{-1,0},{1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
const int mod = 1e9+7;
// const int mod=998244353;
struct mint {
long long x;
mint():x(0) {}
mint(long long x):x((x%mod+mod)%mod) {}
// mint(long long x):x(x){}
mint &fix() { x = (x%mod+mod)%mod; return *this; }
mint operator-() const { return mint(0) - *this; }
mint operator~() const { return mint(1) / *this; }
mint &operator+=(const mint &a) { if ((x+=a.x)>=mod) x-=mod; return *this; }
mint &operator-=(const mint &a) { if ((x+=mod-a.x)>=mod) x-=mod; return *this; }
mint &operator*=(const mint &a) { (x*=a.x)%=mod; return *this; }
mint &operator/=(const mint &a) { (x*=a.pow(mod-2).x)%=mod; return *this; }
mint operator+(const mint &a)const { return mint(*this) += a; }
mint operator-(const mint &a)const { return mint(*this) -= a; }
mint operator*(const mint &a)const { return mint(*this) *= a; }
mint operator/(const mint &a)const { return mint(*this) /= a; }
mint pow(long long t) const {
mint ret=1,cur=x;
for (; t; t>>=1ll,cur=cur*cur)
if (t&1) ret=ret*cur;
return ret;
}
bool operator<(const mint &a)const { return x < a.x; }
bool operator==(const mint &a)const { return x == a.x; }
};
istream & operator>>(istream &o,mint &a) { o>>a.x; a=a.fix(); return o; }
ostream & operator<<(ostream &o,const mint &a) { o<<a.x; return o; }
ll A[107];
void solve() {
int n,k;
scanf("%d%d",&n,&k);
FOR_(i,1,n) scanf("%lld",&A[i]);
// FOR_(i,1,n) A[i]=n-i+1;
// if (n==2) assert(0);
vector<int> res;
auto doit=[&](int x) { // 仅有n=2有可能无解
// printf("doit %d: %d %d; %d\n",x,A[x],A[x+1],res.size());
res.push_back(x);
swap(A[x],A[x+1]);
A[x]+=k;
};
if (A[n-1]>A[n]) {
doit(n-1);
}
if (n>=3) {
FOR_(i,1,200) doit(n-1),doit(n-1);
doit(n-2);
}
FOR_(i,1,n-2) {
while (A[i]>A[i+1]) doit(i+1),doit(i+1);
// printf("i=%d; %d\n",i,res.size());
}
// FOR_(i,1,n) printf("%lld ",A[i]); puts("<- final A");
FOR_(i,1,n-1) if (A[i]>A[i+1]) {
puts("No");
return;
}
puts("Yes");
printf("%d\n",res.size());
for (int v:res) printf("%d ",v);
puts("");
// FOR_(i,1,n) printf("%d ",A[i]); puts("<- final A");
}
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(0), cout.tie(0);
int T = 1;
// cin>>T;
// scanf("%d",&T);
startTimer();
FOR_(_, 1, T) { solve(); }
// printTimer();
}
/*
3 4
1 8 5
*/
Submission Info
| Submission Time |
|
| Task |
A - Add and Swap |
| User |
zlc1114 |
| Language |
C++ 20 (gcc 12.2) |
| Score |
600 |
| Code Size |
4576 Byte |
| Status |
AC |
| Exec Time |
1 ms |
| Memory |
3972 KiB |
Compile Error
Main.cpp: In function ‘void solve()’:
Main.cpp:116:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
116 | printf("%d\n",res.size());
| ~^ ~~~~~~~~~~
| | |
| int std::vector<int>::size_type {aka long unsigned int}
| %ld
Main.cpp:87:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
87 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:88:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
88 | FOR_(i,1,n) scanf("%lld",&A[i]);
| ~~~~~^~~~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
600 / 600 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt, 02_handmade_09.txt, 02_handmade_10.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_01.txt |
AC |
1 ms |
3856 KiB |
| 00_sample_02.txt |
AC |
1 ms |
3716 KiB |
| 01_test_01.txt |
AC |
1 ms |
3700 KiB |
| 01_test_02.txt |
AC |
1 ms |
3700 KiB |
| 01_test_03.txt |
AC |
1 ms |
3864 KiB |
| 01_test_04.txt |
AC |
1 ms |
3696 KiB |
| 01_test_05.txt |
AC |
1 ms |
3808 KiB |
| 01_test_06.txt |
AC |
1 ms |
3576 KiB |
| 01_test_07.txt |
AC |
1 ms |
3864 KiB |
| 01_test_08.txt |
AC |
1 ms |
3816 KiB |
| 01_test_09.txt |
AC |
1 ms |
3700 KiB |
| 01_test_10.txt |
AC |
1 ms |
3820 KiB |
| 01_test_11.txt |
AC |
1 ms |
3860 KiB |
| 01_test_12.txt |
AC |
1 ms |
3720 KiB |
| 01_test_13.txt |
AC |
1 ms |
3724 KiB |
| 01_test_14.txt |
AC |
1 ms |
3812 KiB |
| 01_test_15.txt |
AC |
1 ms |
3720 KiB |
| 01_test_16.txt |
AC |
1 ms |
3740 KiB |
| 01_test_17.txt |
AC |
1 ms |
3740 KiB |
| 01_test_18.txt |
AC |
1 ms |
3840 KiB |
| 01_test_19.txt |
AC |
1 ms |
3620 KiB |
| 01_test_20.txt |
AC |
1 ms |
3828 KiB |
| 01_test_21.txt |
AC |
1 ms |
3808 KiB |
| 01_test_22.txt |
AC |
1 ms |
3972 KiB |
| 01_test_23.txt |
AC |
1 ms |
3868 KiB |
| 01_test_24.txt |
AC |
1 ms |
3748 KiB |
| 01_test_25.txt |
AC |
1 ms |
3856 KiB |
| 01_test_26.txt |
AC |
1 ms |
3728 KiB |
| 01_test_27.txt |
AC |
1 ms |
3808 KiB |
| 01_test_28.txt |
AC |
1 ms |
3572 KiB |
| 01_test_29.txt |
AC |
1 ms |
3772 KiB |
| 01_test_30.txt |
AC |
1 ms |
3852 KiB |
| 01_test_31.txt |
AC |
1 ms |
3904 KiB |
| 01_test_32.txt |
AC |
1 ms |
3780 KiB |
| 01_test_33.txt |
AC |
1 ms |
3520 KiB |
| 01_test_34.txt |
AC |
1 ms |
3688 KiB |
| 01_test_35.txt |
AC |
1 ms |
3908 KiB |
| 01_test_36.txt |
AC |
1 ms |
3880 KiB |
| 02_handmade_01.txt |
AC |
1 ms |
3716 KiB |
| 02_handmade_02.txt |
AC |
1 ms |
3812 KiB |
| 02_handmade_03.txt |
AC |
1 ms |
3820 KiB |
| 02_handmade_04.txt |
AC |
1 ms |
3692 KiB |
| 02_handmade_05.txt |
AC |
1 ms |
3720 KiB |
| 02_handmade_06.txt |
AC |
1 ms |
3696 KiB |
| 02_handmade_07.txt |
AC |
1 ms |
3720 KiB |
| 02_handmade_08.txt |
AC |
1 ms |
3768 KiB |
| 02_handmade_09.txt |
AC |
1 ms |
3912 KiB |
| 02_handmade_10.txt |
AC |
1 ms |
3916 KiB |