P16604 [SYSUCPC 2025] SYSU III
思路
神神原神原神 uu。
贪心找到的串一定合法,但不一定最优,所以答案不会大于正解。
考虑怎么使得贪心得到的值小于正解,只需构造 ssysysuu 这样的一个串,就可以使得贪心的第一个串的第一个 s 用掉了本该给第二个串的第二个 s 导致错误。
扩展一点,s...ys...u... 这样的结构每有两组就会使得贪心比正解少一。
那么我们只需要放 $(y-x)\times 2$ 组 s...ys...u...,再在最后加上 $x$ 组 sysu 就可以了。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include<bits/stdc++.h> #define fir first #define sec second #define int long long #define pii pair<int,int> #define double long double #define fep(i,s,e) for(int i=s;i<e;i++) #define pef(i,s,e) for(int i=s;i>e;i--) #define rep(i,s,e) for(int i=s;i<=e;i++) #define per(i,s,e) for(int i=s;i>=e;i--) namespace FastIO{ template<typename T>inline void read(T &x){ x=0;int f=1;char c=getchar(); for(;!isdigit(c);c=getchar())if(c=='-')f=-1; for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);x*=f; } inline void read(char &c){ c=getchar(); while(isspace(c))c=getchar(); } inline void read(std::string &s){ s.clear();char c=getchar(); for(;isspace(c);c=getchar()); for(;!isspace(c)&&c!=EOF;c=getchar())s+=c; } template<typename T,typename...Args> void read(T &x,Args&...args){ read(x);read(args...); } template<typename T>void print(T x){ if(x<0)x=-x,putchar('-'); if(x>9)print(x/10); putchar((x%10)^48); } inline void print(char c){ putchar(c); } inline void print(std::string s){ fep(i,0,s.size())putchar(s[i]); } inline void print(const char*s){ while(*s)putchar(*s++); } template<typename T,typename...Args> void print(const T &x,const Args&...args){ print(x);print(args...); } } using namespace std; using namespace FastIO; string s; int x,y,del; signed main(){ read(x,y);del=y-x;del*=2; if(del>x*2)return puts("-1"),0; if(del<0)return puts("-1"),0; rep(i,1,del)s+="s"; rep(i,1,del)s+="ys"; rep(i,1,del)s+="u"; rep(i,1,2*x-y)s+="sysu"; print(s); }
|