Idea:MathModel
Divide $$$n$$$ to odd and even
How we can represent palindrome string ?
Denote the sum of segment is $$$f$$$ and sum of medians is $$$h$$$ then $$$m=2f+h$$$
Focus on median when $$$n$$$ is even and use the symmetric property
See the $$$\min$$$ and $$$\max$$$ case for odd and even $$$n$$$
For odd values of $$$n$$$ we can re-express string $$$s$$$ as
Note that $$$s_1+s_2+...+s_{\lfloor \frac{n}{2} \rfloor}=s_{\lceil \frac{n}{2} \rceil+1}+....+s_n$$$ , so we can assume the sum as $$$f$$$.
And let's denote the median digit by $$$h$$$ , thus the sum is $$$2f+h$$$ , it can be shown that $$$h$$$ can be possibly any digit , thus we can construct all sums which lies between minimum and maximum inclusive .
Now Let's do the same for even values of $$$n$$$ we can re-express $$$s$$$ as
Using the symmetric property we can see $$$s_{\lfloor \frac{n}{2} \rfloor}=s_{\lfloor \frac{n}{2} \rfloor+1}$$$ , if we denote one digit by $$$h$$$ thus the sum of medians is $$$2h$$$ and if we denote the left and right segments by $$$f$$$ as we did for odd $$$n$$$ then we have $$$m=2f+2h=2(f+h)$$$ thus for even $$$n$$$ we have an additional condition that sum must be even
Thus Total Complexity for each test case is $$$\mathcal{O}(1)$$$ time .
for _ in range(int(input())):
n,m= map(int, input().split())
if(m >= n and m <= 9 * n and (n % 2 != 0 or m % 2 == 0)):
print("YES")
else:
print("NO")
Idea:MathModel
If $$$x<z$$$, the answer is obviously $$$-1$$$. We only consider the case of $$$x \ge z$$$.
Maximum number of interviews per day can happen is the number of distinct interviews can happen , which is the number of interviewers times the capacity of each interviewer integer divided by the needed interviewers in one interview , Formally
The construction is simple:
consider a sequence of length $$$x \cdot y$$$ — $$$[1,2,\ldots,x,1,2,\ldots,x,\lodts]$$$ , and simply output consecutive segments of length $$$z$$$ in order.
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <random>
#include <chrono>
using namespace std;
#define _int64 long long
#define mo 998244353
int main()
{
int i,j,k,n,l,t,m,x,y,o,b1,z,ans,now;
scanf("%d",&t);
for (l=0;l<t;l++)
{
scanf("%d%d%d",&x,&y,&z);
if (z>x)
{
printf("0\n");
continue;
}
ans=x*y/z;
printf("%d\n",ans);
now=1;
for (i=0;i<ans;i++)
{
for (j=0;j<z;j++)
{
printf("%d ",now);
now++;
if (now>x) now=1;
}
printf("\n");
}
}
}
Idea:imranakki
~ ~~~~~
Idea:MathModel
~~~~~
Idea:wuhudsm
The intended solution is $$$O(n)$$$.
~~~~~
Idea:wuhudsm
~~~~~
~~~~~
Idea:Timosh
~~~~~
~~~~~