exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k ⌀ | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k ⌀ | difficulty int64 -1 3.5k ⌀ | prob_desc_output_spec stringlengths 17 1.47k ⌀ | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 25af8414a3828639d73f7c4b5856c22d | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.*;
public class ChipMove_1716D {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), k = sc.nextInt(), mod = 998244353;
sc.close();
int[] dp = new int[n + 1];
int[] total = new int[n + 1];
dp[0] = 1;
for(int step = 0; step < 640; step ++) {
int[] dp2 = new int[n + 1];
int gap = step + k;
for(int num = 0; num <= n; num ++) {
if(num + gap > n) break;
dp2[num + gap] = (dp2[num] + dp[num]) % mod;
total[num + gap] = (total[num + gap] + dp2[num + gap]) % mod;
}
dp = dp2;
}
StringBuilder output = new StringBuilder();
for(int i = 1; i <= n; i ++) output.append(total[i] + " ");
System.out.println(output.toString());
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 70f1b6b4e864489b9ae320503f7f76c5 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class CF1{
public static void main(String[] args) {
FastScanner sc=new FastScanner();
// hamare saath shree raghunath to kis baat ki chinta...
// int T=sc.nextInt();
int T=1;
for (int tt=1; tt<=T; tt++){
int n =sc.nextInt();
int k =sc.nextInt();
int lim=0;
int sum=0;
int temp=k;
while (sum<n){
lim++;
sum+=temp;
temp++;
}
int prev[]=new int [n+1];
int ans []= new int [n+1];
int curr[]= new int [n+1];
prev[0]=1;
for (int i=0; i<lim; i++){
for (int j=1; j<=n; j++){
if (j>=k){
prev[j]=(prev[j]+prev[j-k])%mod2;
}
}
for (int j=1; j<=n;j++){
if (j>=k) curr[j]=prev[j-k];
ans[j]+=curr[j];
ans[j]%=mod2;
}
prev=curr;
curr= new int [n+1];
k++;
}
StringBuilder sb= new StringBuilder();
for (int i=1; i<=n; i++ ) sb.append(ans[i]+" ");
System.out.println(sb);
}
}
static long prime(long n){
for (long i=3; i*i<=n; i+=2){
if (n%i==0) return i;
}
return -1;
}
static long factorial (int x){
if (x==0) return 1;
long ans =x;
for (int i=x-1; i>=1; i--){
ans*=i;
ans%=mod;
}
return ans;
}
static boolean killMePls = false;
// public static void main(String[] args) throws Exception {
// Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() {
// public void uncaughtException(Thread t, Throwable e) {killMePls = true;}
// };
// Thread t = new Thread(null, ()->A(args), "", 1<<28);
// t.setUncaughtExceptionHandler(h);
// t.start();
// t.join();
// if(killMePls) throw null;
// }
static int mod2= 998244353;
static long mod=1000000007L;
static long power2 (long a, long b){
long res=1;
while (b>0){
if ((b&1)== 1){
res= (res * a % mod)%mod;
}
a=(a%mod * a%mod)%mod;
b=b>>1;
}
return res;
}
static void sort(int[] a){
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void sortLong(long[] a){
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static long gcd (long n, long m){
if (m==0) return n;
else return gcd(m, n%m);
}
static class Pair implements Comparable<Pair>{
int x,y;
private static final int hashMultiplier = BigInteger.valueOf(new Random().nextInt(1000) + 100).nextProbablePrime().intValue();
public Pair(int x, int y){
this.x = x;
this.y = y;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pii = (Pair) o;
if (x != pii.x) return false;
return y == pii.y;
}
public int hashCode() {
return hashMultiplier * x + y;
}
public int compareTo(Pair o){
// if (this.x==o.x) return Integer.compare(this.y,o.y);
// else return Integer.compare(this.x,o.x);
return Integer.compare(this.y,o.y);
}
// this.x-o.x is ascending
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 248bb210f3811a95dae6f21705026878 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.*;
import java.util.concurrent.TimeUnit;
import java.io.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class D1716D{
public static void solve(){
}
public static void main(String args[])throws IOException, ParseException{
Scanner sc=new Scanner(System.in);
int t=1;
while(t-->0){
int mod= (int)998244353;
int n=sc.nextInt();
int k=sc.nextInt();
int dp[]=new int[n+1];
dp[0]=1;
int ans[]=new int[n+1];
for(int m=0;m+k<=n;m+=k++){
int sum[]=new int[k];
// System.out.println(k+" "+m);
for(int i=m;i<=n;i++){
int cur=dp[i];
dp[i]=sum[i%k];
sum[i%k]=(sum[i%k]+cur)%mod;
ans[i]=(ans[i]+dp[i])%mod;
// System.out.print(dp[i]+ " ");
}
// System.out.println();
}
solve();
for(int i=1;i<=n;i++){
System.out.print(ans[i]+" ");
}
}
}
public static <K,V> Map<K,V> getLimitedSizedCache(int size){
/*Returns an unlimited sized map*/
if(size==0){
return (LinkedHashMap<K, V>) Collections.synchronizedMap(new LinkedHashMap<K, V>());
}
/*Returns the map with the limited size*/
Map<K, V> linkedHashMap = Collections.synchronizedMap(new LinkedHashMap<K, V>() {
protected boolean removeEldestEntry(Map.Entry<K, V> eldest)
{
return size() > size;
}
});
return linkedHashMap;
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 0df890e5cbbebd41edf3f67834b1e4f2 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.*;
import java.util.concurrent.TimeUnit;
import java.io.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class D1716D{
public static void solve(){
}
public static void main(String args[])throws IOException, ParseException{
Scanner sc=new Scanner(System.in);
int t=1;
while(t-->0){
int mod= (int)998244353;
int n=sc.nextInt();
int k=sc.nextInt();
int dp[]=new int[n+1];
dp[0]=1;
int ans[]=new int[n+1];
for(int m=0;m+k<=n;m+=k++){
int sum[]=new int[k];
// System.out.println(k+" "+m);
for(int i=m;i<=n;i++){
int cur=dp[i];
dp[i]=sum[i%k];
sum[i%k]=(sum[i%k]+cur)%mod;
ans[i]=(ans[i]+dp[i])%mod;
// System.out.print(dp[i]+ " ");
}
// System.out.println();
}
solve();
for(int i=1;i<=n;i++){
System.out.print(ans[i]+" ");
}
}
}
public static <K,V> Map<K,V> getLimitedSizedCache(int size){
/*Returns an unlimited sized map*/
if(size==0){
return (LinkedHashMap<K, V>) Collections.synchronizedMap(new LinkedHashMap<K, V>());
}
/*Returns the map with the limited size*/
Map<K, V> linkedHashMap = Collections.synchronizedMap(new LinkedHashMap<K, V>() {
protected boolean removeEldestEntry(Map.Entry<K, V> eldest)
{
return size() > size;
}
});
return linkedHashMap;
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 7f4b92ae2a54b4ad8a34997c8df3142a | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.*;
import java.util.concurrent.TimeUnit;
import java.io.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class D1716D{
public static void solve(){
}
public static void main(String args[])throws IOException, ParseException{
Scanner sc=new Scanner(System.in);
int t=1;
while(t-->0){
int mod= (int)998244353;
int n=sc.nextInt();
int k=sc.nextInt();
int dp[]=new int[n+1];
dp[0]=1;
int ans[]=new int[n+1];
for(int m=0;m+k<=n;m+=k++){
int sum[]=new int[k];
// System.out.println(k+" "+m);
for(int i=m;i<=n;i++){
int cur=dp[i];
dp[i]=sum[i%k];
sum[i%k]=(sum[i%k]+cur)%mod;
ans[i]=(ans[i]+dp[i])%mod;
// System.out.print(dp[i]+ " ");
}
// System.out.println();
}
solve();
for(int i=1;i<=n;i++){
System.out.print(ans[i]+" ");
}
}
}
public static <K,V> Map<K,V> getLimitedSizedCache(int size){
/*Returns an unlimited sized map*/
if(size==0){
return (LinkedHashMap<K, V>) Collections.synchronizedMap(new LinkedHashMap<K, V>());
}
/*Returns the map with the limited size*/
Map<K, V> linkedHashMap = Collections.synchronizedMap(new LinkedHashMap<K, V>() {
protected boolean removeEldestEntry(Map.Entry<K, V> eldest)
{
return size() > size;
}
});
return linkedHashMap;
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 4fd4e7b5d59277328a7a32a11aec4216 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
int mod=998244353;
int n=cin.nextInt(),k=cin.nextInt();
int dp[]=new int[n+1];
int ans[]=new int[n+1];
int step=k;
dp[0]=1;
for(int i=k;i<=n;step++,i+=step) {
int cur[]=new int[n+1];//当前走的方案数
//初始定义
for(int j=step;j<=n;j++)cur[j]=dp[j-step];
for(int j=i+step;j<=n;j++) {
cur[j]=(cur[j]+cur[j-step])%mod;
}
for(int j=i;j<=n;j++) {
ans[j]=(ans[j]+cur[j])%mod;
}
dp=cur;
}
for(int i=1;i<=n;i++) {
if(i>1)out.print(" ");
out.print(ans[i]);
}
out.println();
out.flush();
}
static class FastScanner{
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream in) {
br=new BufferedReader( new InputStreamReader(System.in));
eat("");
}
public void eat(String s) {
st=new StringTokenizer(s);
}
public String nextLine() {
try {
return br.readLine();
}catch(IOException e) {
return null;
}
}
public boolean hasNext() {
while(!st.hasMoreTokens()) {
String s=nextLine();
if(s==null)return false;
eat(s);
}
return true;
}
public String next() {
hasNext();
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
static FastScanner cin=new FastScanner(System.in);
static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | b667e93cbd057f1a38865352d8b722f6 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes |
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class dd {
static int mod = 998244353;
static Read s = new Read();
static int n;
public static void main(String[] args) throws IOException {
int n = s.nextInt();
int k = s.nextInt();
int[] dp = new int[n + 1];
int[] prev = new int[n + 1];
dp[0] = prev[0] = 1;
for (int i = 0; i < n; k++) {
i += k;
int[] cur = new int[n + 1];
for (int j = i; j <= n; j++) {
cur[j] += cur[j - k] + prev[j - k];
cur[j] %= mod;
dp[j] += cur[j];
dp[j] %= mod;
}
prev = cur;
}
for (int i = 1; i <= n; i++) {
s.print(dp[i]+" ");
}
s.bw.flush();
}
static class Input {
BufferedReader reader;
StringTokenizer tokenizer;
Input(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
boolean hasMore() throws IOException {
if (tokenizer.hasMoreTokens()) return true;
else {
String s = reader.readLine();
if (s == null) return false;
else {
tokenizer = new StringTokenizer(s);
return true;
}
}
}
}//用于输入多组数据
static class Read {
BufferedReader bf;
StringTokenizer st;
BufferedWriter bw;
public Read() {
bf = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public String nextLine() throws IOException {
return bf.readLine();
}
public String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public float nextFloat() throws IOException {
return Float.parseFloat(next());
}
public byte nextByte() throws IOException {
return Byte.parseByte(next());
}
public short nextShort() throws IOException {
return Short.parseShort(next());
}
public BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}
public void println(int a) throws IOException {
bw.write(String.valueOf(a));
bw.newLine();
return;
}
public void print(int a) throws IOException {
bw.write(String.valueOf(a));
return;
}
public void println(String a) throws IOException {
bw.write(a);
bw.newLine();
return;
}
public void print(String a) throws IOException {
bw.write(a);
return;
}
public void println(long a) throws IOException {
bw.write(String.valueOf(a));
bw.newLine();
return;
}
public void print(long a) throws IOException {
bw.write(String.valueOf(a));
return;
}
public void println(double a) throws IOException {
bw.write(String.valueOf(a));
bw.newLine();
return;
}
public void print(double a) throws IOException {
bw.write(String.valueOf(a));
return;
}
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 8 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 03607331d715f15ccfda126f2f5625ae | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.*;
import java.io.*;
public class D {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next(){
while (st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() throws IOException{
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] nextArray(int n){
int[] a = new int[n];
for(int i = 0; i < n; i++){
a[i] = Integer.parseInt(next());
}
return a;
}
}
public static void main(String[] args) throws IOException
{
// System.setIn(new FileInputStream(new File("/Users/pluo/Desktop/CF/input.txt")));
// System.setOut(new PrintStream(new File("/Users/pluo/Desktop/CF/output.txt")));
FastReader sc = new FastReader();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int n = sc.nextInt();
int k = sc.nextInt();
int MOD = 998244353;
int m = k;
int sum = 0;
while(sum+m <= n){
sum += m;
m++;
}
int[][] dp = new int[2][n-k+1];
int[] ans = new int[n-k+1];
for(int i = 0; i < n-k+1; i += k){
dp[0][i] = 1;
ans[i] = 1;
}
for(int i = 1; i < m-k; i++){
int a = i % 2;
int b = a ^ 1;
for(int j = 0; j <= n-k; j++){
if(j-i-k >= 0){
dp[a][j] = dp[a][j-i-k] + dp[b][j-i-k];
dp[a][j] %= MOD;
}
else{
dp[a][j] = 0;
}
ans[j] += dp[a][j];
ans[j] %= MOD;
}
}
out.write("0 ".repeat(k-1));
for(int i = 0; i <= n-k; i++){
out.write(ans[i] + " ");
}
out.flush();
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 17 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 6580b1a6cd4ff401b78481a204db8ed4 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
public class ChipMove {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String[] input = br.readLine().split(" ");
int n = Integer.parseInt(input[0]);
int k = Integer.parseInt(input[1]);
int mod = 998244353;
int[] cache = new int[n + 1];
int[] answers = new int[n + 1];
cache[0] = 1;
answers[0] = 0;
int[] modCounts;
for (int j = 0; j * j <= 2 * n; j++) {
int m = j + k;
modCounts = new int[m];
for (int i = 0; i <= n; i++) {
int x = cache[i];
cache[i] = modCounts[i % m];
cache[i] %= mod;
modCounts[i % m] += x;
modCounts[i % m] %= mod;
answers[i] += x;
answers[i] %= mod;
}
}
for (int i = 1; i <= n; i++) {
bw.write(answers[i] + " ");
}
br.close();
bw.close();
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 17 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 7cbfab384b89a89094c50883c7b82825 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.*;
import java.util.function.*;
import java.io.*;
// you can compare with output.txt and expected out
public class RoundEdu133D {
MyPrintWriter out;
MyScanner in;
// final static long FIXED_RANDOM;
// static {
// FIXED_RANDOM = System.currentTimeMillis();
// }
final static String IMPOSSIBLE = "IMPOSSIBLE";
final static String POSSIBLE = "POSSIBLE";
final static String YES = "YES";
final static String NO = "NO";
private void initIO(boolean isFileIO) {
if (System.getProperty("ONLINE_JUDGE") == null && isFileIO) {
try{
in = new MyScanner(new FileInputStream("input.txt"));
out = new MyPrintWriter(new FileOutputStream("output.txt"));
}
catch(FileNotFoundException e){
e.printStackTrace();
}
}
else{
in = new MyScanner(System.in);
out = new MyPrintWriter(new BufferedOutputStream(System.out));
}
}
public static void main(String[] args){
// Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
RoundEdu133D sol = new RoundEdu133D();
sol.run();
}
private void run() {
boolean isDebug = false;
boolean isFileIO = true;
boolean hasMultipleTests = false;
initIO(isFileIO);
int t = hasMultipleTests? in.nextInt() : 1;
for (int i = 1; i <= t; ++i) {
if(isDebug){
out.printf("Test %d\n", i);
}
getInput();
solve();
printOutput();
}
in.close();
out.close();
}
final long MOD = 998244353;
// use suitable one between matrix(2, n) or matrix(n, 2) for graph edges, pairs, ...
int n, k;
void getInput() {
n = in.nextInt();
k = in.nextInt();
}
void printOutput() {
out.printlnAns(ans);
}
long[] ans;
void solve(){
ans = new long[n];
// ans[x] = for x+1
// k + k+1 + k+2 + ... + k+l <= n
int sum = 0;
int sq;
for(sq=0; sum <=n; sq++)
sum += k+sq;
long[][] dp = new long[2][n+1];
{
for(int step = k; step <= n; step += k) {
dp[0][step] = 1;
ans[step-1] = 1;
}
}
// for each x
// for each j < sq (the type of last move)
// you decide step (x/(k+j))
int first = k;
for(int j=1; j<sq; j++) { // sqrt(n)
int parity = j%2;
int step = k+j;
first += step;
for(int i=first; i<=n; i++) {
long val = dp[0][i-step] + dp[1][i-step];
dp[parity][i] = val>=MOD? val-MOD: val;
ans[i-1] += dp[parity][i];
}
Arrays.fill(dp[1-parity], 0);
}
for(int i=0; i<n; i++)
ans[i] %= MOD;
}
static class Pair implements Comparable<Pair>{
final static long FIXED_RANDOM = System.currentTimeMillis();
int first, second;
public Pair(int first, int second) {
this.first = first;
this.second = second;
}
@Override
public int hashCode() {
// http://xorshift.di.unimi.it/splitmix64.c
long x = first;
x <<= 32;
x += second;
x += FIXED_RANDOM;
x += 0x9e3779b97f4a7c15l;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9l;
x = (x ^ (x >> 27)) * 0x94d049bb133111ebl;
return (int)(x ^ (x >> 31));
}
@Override
public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
Pair other = (Pair) obj;
return first == other.first && second == other.second;
}
@Override
public String toString() {
return "[" + first + "," + second + "]";
}
@Override
public int compareTo(Pair o) {
int cmp = Integer.compare(first, o.first);
return cmp != 0? cmp: Integer.compare(second, o.second);
}
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
// 32768?
public MyScanner(InputStream is, int bufferSize) {
br = new BufferedReader(new InputStreamReader(is), bufferSize);
}
public MyScanner(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
// br = new BufferedReader(new InputStreamReader(System.in));
// br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
}
public void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[][] nextMatrix(int n, int m) {
return nextMatrix(n, m, 0);
}
int[][] nextMatrix(int n, int m, int offset) {
int[][] mat = new int[n][m];
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
mat[i][j] = nextInt()+offset;
}
}
return mat;
}
int[] nextIntArray(int len) {
return nextIntArray(len, 0);
}
int[] nextIntArray(int len, int offset){
int[] a = new int[len];
for(int j=0; j<len; j++)
a[j] = nextInt()+offset;
return a;
}
long[] nextLongArray(int len) {
return nextLongArray(len, 0);
}
long[] nextLongArray(int len, int offset){
long[] a = new long[len];
for(int j=0; j<len; j++)
a[j] = nextLong()+offset;
return a;
}
String[] nextStringArray(int len) {
String[] s = new String[len];
for(int i=0; i<len; i++)
s[i] = next();
return s;
}
}
public static class MyPrintWriter extends PrintWriter{
public MyPrintWriter(OutputStream os) {
super(os);
}
public void printlnAns(long ans) {
println(ans);
}
public void printlnAns(int ans) {
println(ans);
}
public void printlnAns(boolean ans) {
if(ans)
println(YES);
else
println(NO);
}
public void printAns(long[] arr){
if(arr != null && arr.length > 0){
print(arr[0]);
for(int i=1; i<arr.length; i++){
print(" ");
print(arr[i]);
}
}
}
public void printlnAns(long[] arr){
printAns(arr);
println();
}
public void printAns(int[] arr){
if(arr != null && arr.length > 0){
print(arr[0]);
for(int i=1; i<arr.length; i++){
print(" ");
print(arr[i]);
}
}
}
public void printlnAns(int[] arr){
printAns(arr);
println();
}
public <T> void printAns(ArrayList<T> arr){
if(arr != null && arr.size() > 0){
print(arr.get(0));
for(int i=1; i<arr.size(); i++){
print(" ");
print(arr.get(i));
}
}
}
public <T> void printlnAns(ArrayList<T> arr){
printAns(arr);
println();
}
public void printAns(int[] arr, int add){
if(arr != null && arr.length > 0){
print(arr[0]+add);
for(int i=1; i<arr.length; i++){
print(" ");
print(arr[i]+add);
}
}
}
public void printlnAns(int[] arr, int add){
printAns(arr, add);
println();
}
public void printAns(ArrayList<Integer> arr, int add) {
if(arr != null && arr.size() > 0){
print(arr.get(0)+add);
for(int i=1; i<arr.size(); i++){
print(" ");
print(arr.get(i)+add);
}
}
}
public void printlnAns(ArrayList<Integer> arr, int add){
printAns(arr, add);
println();
}
public void printlnAnsSplit(long[] arr, int split){
if(arr != null){
for(int i=0; i<arr.length; i+=split){
print(arr[i]);
for(int j=i+1; j<i+split; j++){
print(" ");
print(arr[j]);
}
println();
}
}
}
public void printlnAnsSplit(int[] arr, int split){
if(arr != null){
for(int i=0; i<arr.length; i+=split){
print(arr[i]);
for(int j=i+1; j<i+split; j++){
print(" ");
print(arr[j]);
}
println();
}
}
}
public <T> void printlnAnsSplit(ArrayList<T> arr, int split){
if(arr != null && !arr.isEmpty()){
for(int i=0; i<arr.size(); i+=split){
print(arr.get(i));
for(int j=i+1; j<i+split; j++){
print(" ");
print(arr.get(j));
}
println();
}
}
}
}
static private void permutateAndSort(long[] a) {
int n = a.length;
Random R = new Random(System.currentTimeMillis());
for(int i=0; i<n; i++) {
int t = R.nextInt(n-i);
long temp = a[n-1-i];
a[n-1-i] = a[t];
a[t] = temp;
}
Arrays.sort(a);
}
static private void permutateAndSort(int[] a) {
int n = a.length;
Random R = new Random(System.currentTimeMillis());
for(int i=0; i<n; i++) {
int t = R.nextInt(n-i);
int temp = a[n-1-i];
a[n-1-i] = a[t];
a[t] = temp;
}
Arrays.sort(a);
}
static private int[][] constructChildren(int n, int[] parent, int parentRoot){
int[][] childrens = new int[n][];
int[] numChildren = new int[n];
for(int i=0; i<parent.length; i++) {
if(parent[i] != parentRoot)
numChildren[parent[i]]++;
}
for(int i=0; i<n; i++) {
childrens[i] = new int[numChildren[i]];
}
int[] idx = new int[n];
for(int i=0; i<parent.length; i++) {
if(parent[i] != parentRoot)
childrens[parent[i]][idx[parent[i]]++] = i;
}
return childrens;
}
static private int[][][] constructDirectedNeighborhood(int n, int[][] e){
int[] inDegree = new int[n];
int[] outDegree = new int[n];
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
outDegree[u]++;
inDegree[v]++;
}
int[][] inNeighbors = new int[n][];
int[][] outNeighbors = new int[n][];
for(int i=0; i<n; i++) {
inNeighbors[i] = new int[inDegree[i]];
outNeighbors[i] = new int[outDegree[i]];
}
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
outNeighbors[u][--outDegree[u]] = v;
inNeighbors[v][--inDegree[v]] = u;
}
return new int[][][] {inNeighbors, outNeighbors};
}
static private int[][] constructNeighborhood(int n, int[][] e) {
int[] degree = new int[n];
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
degree[u]++;
degree[v]++;
}
int[][] neighbors = new int[n][];
for(int i=0; i<n; i++)
neighbors[i] = new int[degree[i]];
for(int i=0; i<e.length; i++) {
int u = e[i][0];
int v = e[i][1];
neighbors[u][--degree[u]] = v;
neighbors[v][--degree[v]] = u;
}
return neighbors;
}
static private void drawGraph(int[][] e) {
makeDotUndirected(e);
try {
final Process process = new ProcessBuilder("dot", "-Tpng", "graph.dot")
.redirectOutput(new File("graph.png"))
.start();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
static private void makeDotUndirected(int[][] e) {
MyPrintWriter out2 = null;
try {
out2 = new MyPrintWriter(new FileOutputStream("graph.dot"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
out2.println("strict graph {");
for(int i=0; i<e.length; i++){
out2.println(e[i][0] + "--" + e[i][1] + ";");
}
out2.println("}");
out2.close();
}
static private void makeDotDirected(int[][] e) {
MyPrintWriter out2 = null;
try {
out2 = new MyPrintWriter(new FileOutputStream("graph.dot"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
out2.println("strict digraph {");
for(int i=0; i<e.length; i++){
out2.println(e[i][0] + "->" + e[i][1] + ";");
}
out2.println("}");
out2.close();
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 17 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 1058a7919f528112081162b8c1591214 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class ChipMove {
private static final int MOD = 998244353;
public static void solve(FastIO io) {
final int N = io.nextInt();
final int K = io.nextInt();
int[] ans = new int[N + 1];
int[] ways = new int[N + 1];
int[] next = new int[N + 1];
ways[0] = 1;
int kMax = K;
int kSum = K;
while (kSum <= N) {
++kMax;
kSum += kMax;
}
for (int k = K; k <= kMax; ++k) {
Arrays.fill(next, 0);
for (int off = 0; off < k; ++off) {
int preSum = 0;
for (int i = off; i + k <= N; i += k) {
preSum = add(preSum, ways[i]);
next[i + k] = preSum;
}
}
for (int i = 1; i <= N; ++i) {
ans[i] = add(ans[i], next[i]);
}
int[] tmp = ways;
ways = next;
next = tmp;
}
io.printlnArray(Arrays.copyOfRange(ans, 1, N + 1));
}
private static int add(int a, int b) {
int val = a + b;
if (val >= MOD) {
val -= MOD;
}
return val;
}
public static class FastIO {
private InputStream reader;
private PrintWriter writer;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastIO(InputStream r, OutputStream w) {
reader = r;
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = reader.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
// TODO: read this byte-by-byte like the other read functions.
public double nextDouble() {
return Double.parseDouble(nextString());
}
public int[] nextIntArray(int n) {
return nextIntArray(n, 0);
}
public int[] nextIntArray(int n, int off) {
int[] arr = new int[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
return nextLongArray(n, 0);
}
public long[] nextLongArray(int n, int off) {
long[] arr = new long[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printArray(long[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printlnArray(int[] arr) {
printArray(arr);
writer.println();
}
public void printlnArray(long[] arr) {
printArray(arr);
writer.println();
}
public void printf(String format, Object... args) {
print(String.format(format, args));
}
public void flush() {
writer.flush();
}
}
public static void main(String[] args) {
FastIO io = new FastIO(System.in, System.out);
solve(io);
io.flush();
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 17 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | bad8599cfad56a813c8ca9e635bb5869 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class D {
Input in;
PrintWriter out;
public D() {
in = new Input(System.in);
out = new PrintWriter(System.out);
}
public static void main(String[] args) {
D solution = new D();
solution.solve();
solution.out.close();
}
void solve() {
int n = in.nextInt();
int k = in.nextInt();
final int mod = 998244353;
// dp[i][j] = # of ways to reach position 'i' in 'j' steps
// note, we must step a non-zero distance
int[] curr = new int[n+1];
curr[0] = 1;
int[] ans = new int[n+1];
int maxJump = k;
for (int step=1; maxJump<=n; step++) {
int[] next = new int[n + 1];
maxJump += k + step;
int q = k + step - 1;
for (int i = q; i<n+1; i++) {
next[i] = next[i-q] + curr[i-q];
next[i] %= mod;
ans[i] += next[i];
ans[i] %= mod;
}
curr = next;
}
for (int i=1; i<=n; i++) {
out.print(ans[i]);
out.print(' ');
}
out.println();
}
static class Input {
BufferedReader br;
StringTokenizer st;
public Input(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
st = new StringTokenizer("");
}
String nextString() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextString());
}
long nextLong() {
return Long.parseLong(nextString());
}
int[] nextIntArray(int size) {
int[] ans = new int[size];
for (int i = 0; i < size; i++) {
ans[i] = nextInt();
}
return ans;
}
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 17 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 0cbbbb3229f1d4261b0dd9f0f4bac18f | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class D {
Input in;
PrintWriter out;
public D() {
in = new Input(System.in);
out = new PrintWriter(System.out);
}
public static void main(String[] args) {
D solution = new D();
solution.solve();
solution.out.close();
}
void solve() {
int n = in.nextInt();
int k = in.nextInt();
final int mod = 998244353;
// dp[i][j] = # of ways to reach position 'i' in 'j' steps
// note, we must step a non-zero distance
int[] curr = new int[n+1];
curr[0] = 1;
int[] ans = new int[n+1];
int maxJump = k;
for (int step=1; maxJump<=n; step++) {
int[] next = new int[n + 1];
maxJump += k + step;
int q = k + step - 1;
for (int i = 1; i<n+1; i++) {
if (i-q >= 0) {
next[i] = next[i-q] + curr[i-q];
next[i] %= mod;
}
ans[i] += next[i];
ans[i] %= mod;
}
curr = next;
}
for (int i=1; i<=n; i++) {
out.print(ans[i]);
out.print(' ');
}
out.println();
}
static class Input {
BufferedReader br;
StringTokenizer st;
public Input(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
st = new StringTokenizer("");
}
String nextString() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextString());
}
long nextLong() {
return Long.parseLong(nextString());
}
int[] nextIntArray(int size) {
int[] ans = new int[size];
for (int i = 0; i < size; i++) {
ans[i] = nextInt();
}
return ans;
}
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 17 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | e9b4b9b5620ecfda687d6f9e943a946e | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class CF1716D extends PrintWriter {
CF1716D() { super(System.out, true); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1716D o = new CF1716D(); o.main(); o.flush();
}
static final int MD = 998244353;
void main() {
int n = sc.nextInt();
int k = sc.nextInt();
int[] aa = new int[n + 1];
int[] dp = new int[n + 1];
int[] dq = new int[n + 1];
dp[0] = 1;
for (int x = k; x <= n; x += ++k) {
Arrays.fill(dq, 0);
for (int i = x; i <= n; i++) {
dq[i] = (dp[i - k] + dq[i - k]) % MD;
aa[i] = (aa[i] + dq[i]) % MD;
}
int[] tmp = dp; dp = dq; dq = tmp;
}
for (int i = 1; i <= n; i++)
print(aa[i] + " ");
println();
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 17 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | b4944967374d628774df79d5afe514d5 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | // package c1716;
//
// Educational Codeforces Round 133 (Rated for Div. 2) 2022-08-04 07:35
// D. Chip Move
// https://codeforces.com/contest/1716/problem/D
// time limit per test 2 seconds; memory limit per test 256 megabytes
// public class Pseudo for 'Source should satisfy regex [^{}]*public\s+(final)?\s*class\s+(\w+).*'
//
// There is a chip on the coordinate line. Initially, the chip is located at the point 0. You can
// perform any number of moves; each move increases the coordinate of the chip by some positive
// integer (which is called ). The length of the first move you make should be divisible by k, the
// length of the second move-- by k+1, the third-- by k+2, and so on.
//
// For example, if k=2, then the sequence of moves may look like this: 0 -> 4 -> 7 -> 19 -> 44,
// because 4 - 0 = 4 is divisible by 2 = k, 7 - 4 = 3 is divisible by 3 = k + 1, 19 - 7 = 12 is
// divisible by 4 = k + 2, 44 - 19 = 25 is divisible by 5 = k + 3.
//
// You are given two positive integers n and k. Your task is to count the number of ways to reach
// the point x, starting from 0, for every x \in [1, n]. The number of ways can be very large, so
// print it modulo 998244353. Two ways are considered different if they differ as sets of visited
// positions.
//
// Input
//
// The first (and only) line of the input contains two integers n and k (1 <= k <= n <= 2 * 10^5).
//
// Output
//
// Print n integers-- the number of ways to reach the point x, starting from 0, for every x \in [1,
// n], taken modulo 998244353.
//
// Example
/*
input:
8 1
output:
1 1 2 2 3 4 5 6
input:
10 2
output:
0 1 0 1 1 1 1 2 2 2
*/
// Note
//
// Let's look at the first example:
//
// Ways to reach the point 1: [0, 1];
//
// Ways to reach the point 2: [0, 2];
//
// Ways to reach the point 3: [0, 1, 3], [0, 3];
//
// Ways to reach the point 4: [0, 2, 4], [0, 4];
//
// Ways to reach the point 5: [0, 1, 5], [0, 3, 5], [0, 5];
//
// Ways to reach the point 6: [0, 1, 3, 6], [0, 2, 6], [0, 4, 6], [0, 6];
//
// Ways to reach the point 7: [0, 2, 4, 7], [0, 1, 7], [0, 3, 7], [0, 5, 7], [0, 7];
//
// Ways to reach the point 8: [0, 3, 5, 8], [0, 1, 5, 8], [0, 2, 8], [0, 4, 8], [0, 6, 8], [0, 8].
//
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class C1716D {
static final int MOD = 998244353;
static final Random RAND = new Random();
// *** use int[] instead of long reduced time in test (200000,1) from 463 to 422 msec ***
static int[] solve(int n, int k) {
// dp[v] is qualified ways to reach v after current steps
int[] curr = new int[n + 1];
int[] next = new int[n + 1];
curr[0] = 1;
// System.out.format(" 1 curr:%s\n", Arrays.toString(curr));
int b = 0;
int[] ans = new int[n];
for (int s = 0; s < 1000; s++) {
while (b <= n && curr[b] == 0) {
b++;
}
if (b > n) {
break;
}
int d = k + s;
// consider d modular classes
// b b+d b+2d ...
// b+1 b+d+1 b+2d+1
// ...
// b+d-1 b+d+d-1
for (int j = 0; j < d; j++) {
if (b + j > n) {
break;
}
// b+j b+d+j ... b+(m-1)d + j
int idx = b + j;
int sum = curr[idx];
while (idx + d <= n) {
idx += d;
// contribute sum to next[idx]
next[idx] = (next[idx] + sum) % MOD;
sum = (sum + curr[idx]) % MOD;
}
}
b += d;
Arrays.fill(curr, 0);
int[] t = curr;
curr = next;
next = t;
//System.out.format(" d:%d curr:%s\n", d, Arrays.toString(curr));
// merge here is faster (466 vs 549 msec) than update ans[idx-1] above
merge(curr, ans, b-1);
}
return ans;
}
static void merge(int[] curr, int[] ans, int b) {
int n = ans.length;
for (int i = b; i < n; i++) {
ans[i] = (ans[i] + curr[i+1]) % MOD;
}
}
// Time limit exceeded on test 6
static int[] solveC(int n, int k) {
// use int[] instead of long[]
int[][] mp = new int[n+1][];
mp[0] = new int[1];
mp[0][0] = 1;
int[] ans = new int[n];
for (int h = 0; h <= n; h++) {
if (mp[h] == null) {
continue;
}
int[] a = mp[h];
long sum = 0;
for (long v : a) {
sum += v;
}
if (h > 0) {
ans[h-1] = (int) (sum % MOD);
}
for (int i = a.length - 1; i >= 0; i--) {
if (a[i] == 0) {
continue;
}
int k1 = h + k + i + 1;
if (h > 0 && k1 <= n) {
if (mp[k1] == null) {
mp[k1] = new int[a.length + 1];
}
int[] v1 = mp[k1];
v1[i + 1] = (v1[i + 1] + a[i]) % MOD;
}
int k0 = h + i + k;
if (k0 <= n) {
if (mp[k0] == null) {
mp[k0] = new int[a.length];
}
int[] v0 = mp[k0];
v0[i] = (v0[i] + a[i]) % MOD;
}
}
// System.out.format(" len:%2d\n%s\n", len, Utils.traceMapInt2LongArray(mp));
// System.out.format(" len:%d size:%d\n", len, mp.size());
mp[h] = null;
}
return ans;
}
static boolean test = false;
static void doTest() {
if (!test) {
return;
}
long t0 = System.currentTimeMillis();
// output(solve(10,2));
// output(solve(25252, 11));
// output(solve(30, 1));
output(solve(200000, 1));
System.out.format("%d msec\n", System.currentTimeMillis() - t0);
System.exit(0);
}
public static void main(String[] args) {
doTest();
MyScanner in = new MyScanner();
int n = in.nextInt();
int k = in.nextInt();
int[] ans = solve(n, k);
output(ans);
}
static void output(int[] a) {
StringBuilder sb = new StringBuilder();
for (int v : a) {
sb.append(v);
sb.append(' ');
if (sb.length() > 4000) {
System.out.print(sb.toString());
sb.setLength(0);
}
}
System.out.println(sb.toString());
}
static void myAssert(boolean cond) {
if (!cond) {
throw new RuntimeException("Unexpected");
}
}
static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
try {
final String USERDIR = System.getProperty("user.dir");
String cname = MethodHandles.lookup().lookupClass().getCanonicalName().replace(".MyScanner", "");
cname = cname.lastIndexOf('.') > 0 ? cname.substring(cname.lastIndexOf('.') + 1) : cname;
final File fin = new File(USERDIR + "/io/c" + cname.substring(1,5) + "/" + cname + ".in");
br = new BufferedReader(new InputStreamReader(fin.exists()
? new FileInputStream(fin) : System.in));
} catch (Exception e) {
br = new BufferedReader(new InputStreamReader(System.in));
}
}
public String next() {
try {
while (st == null || !st.hasMoreElements()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | ba442e47a004ac85d79ef249f6789040 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | // package c1716;
//
// Educational Codeforces Round 133 (Rated for Div. 2) 2022-08-04 07:35
// D. Chip Move
// https://codeforces.com/contest/1716/problem/D
// time limit per test 2 seconds; memory limit per test 256 megabytes
// public class Pseudo for 'Source should satisfy regex [^{}]*public\s+(final)?\s*class\s+(\w+).*'
//
// There is a chip on the coordinate line. Initially, the chip is located at the point 0. You can
// perform any number of moves; each move increases the coordinate of the chip by some positive
// integer (which is called ). The length of the first move you make should be divisible by k, the
// length of the second move-- by k+1, the third-- by k+2, and so on.
//
// For example, if k=2, then the sequence of moves may look like this: 0 -> 4 -> 7 -> 19 -> 44,
// because 4 - 0 = 4 is divisible by 2 = k, 7 - 4 = 3 is divisible by 3 = k + 1, 19 - 7 = 12 is
// divisible by 4 = k + 2, 44 - 19 = 25 is divisible by 5 = k + 3.
//
// You are given two positive integers n and k. Your task is to count the number of ways to reach
// the point x, starting from 0, for every x \in [1, n]. The number of ways can be very large, so
// print it modulo 998244353. Two ways are considered different if they differ as sets of visited
// positions.
//
// Input
//
// The first (and only) line of the input contains two integers n and k (1 <= k <= n <= 2 * 10^5).
//
// Output
//
// Print n integers-- the number of ways to reach the point x, starting from 0, for every x \in [1,
// n], taken modulo 998244353.
//
// Example
/*
input:
8 1
output:
1 1 2 2 3 4 5 6
input:
10 2
output:
0 1 0 1 1 1 1 2 2 2
*/
// Note
//
// Let's look at the first example:
//
// Ways to reach the point 1: [0, 1];
//
// Ways to reach the point 2: [0, 2];
//
// Ways to reach the point 3: [0, 1, 3], [0, 3];
//
// Ways to reach the point 4: [0, 2, 4], [0, 4];
//
// Ways to reach the point 5: [0, 1, 5], [0, 3, 5], [0, 5];
//
// Ways to reach the point 6: [0, 1, 3, 6], [0, 2, 6], [0, 4, 6], [0, 6];
//
// Ways to reach the point 7: [0, 2, 4, 7], [0, 1, 7], [0, 3, 7], [0, 5, 7], [0, 7];
//
// Ways to reach the point 8: [0, 3, 5, 8], [0, 1, 5, 8], [0, 2, 8], [0, 4, 8], [0, 6, 8], [0, 8].
//
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Random;
import java.util.StringTokenizer;
public class C1716D {
static final int MOD = 998244353;
static final Random RAND = new Random();
// 702 msec
// 660 msec --- use int[] instead of long
static int[] solveC(int n, int k) {
int[][] mp = new int[n+1][];
mp[0] = new int[1];
mp[0][0] = 1;
int[] ans = new int[n];
for (int h = 0; h <= n; h++) {
if (mp[h] == null) {
continue;
}
int[] a = mp[h];
long sum = 0;
for (long v : a) {
sum += v;
}
if (h > 0) {
ans[h-1] = (int) (sum % MOD);
}
for (int i = a.length - 1; i >= 0; i--) {
if (a[i] == 0) {
continue;
}
int k1 = h + k + i + 1;
if (h > 0 && k1 <= n) {
if (mp[k1] == null) {
mp[k1] = new int[a.length + 1];
}
int[] v1 = mp[k1];
v1[i + 1] = (v1[i + 1] + a[i]) % MOD;
}
int k0 = h + i + k;
if (k0 <= n) {
if (mp[k0] == null) {
mp[k0] = new int[a.length];
}
int[] v0 = mp[k0];
v0[i] = (v0[i] + a[i]) % MOD;
}
}
// System.out.format(" len:%2d\n%s\n", len, Utils.traceMapInt2LongArray(mp));
// System.out.format(" len:%d size:%d\n", len, mp.size());
mp[h] = null;
}
return ans;
}
static int[] solveB(int n, int k) {
int[][] mp = new int[n+1][];
Cache cache = new Cache();
mp[0] = cache.allocate();
mp[0][0] = 1;
int[] ans = new int[n];
for (int h = 0; h <= n; h++) {
if (mp[h] == null) {
continue;
}
int[] a = mp[h];
long sum = 0;
for (long v : a) {
sum += v;
}
if (h > 0) {
ans[h-1] = (int) (sum % MOD);
}
for (int i = a.length - 1; i >= 0; i--) {
if (a[i] == 0) {
continue;
}
int k1 = h + k + i + 1;
if (h > 0 && k1 <= n) {
if (mp[k1] == null) {
mp[k1] = cache.allocate();
}
int[] v1 = mp[k1];
v1[i + 1] = (v1[i + 1] + a[i]) % MOD;
}
int k0 = h + i + k;
if (k0 <= n) {
if (mp[k0] == null) {
mp[k0] = cache.allocate();
}
int[] v0 = mp[k0];
v0[i] = (v0[i] + a[i]) % MOD;
}
}
// System.out.format(" len:%2d\n%s\n", len, Utils.traceMapInt2LongArray(mp));
// System.out.format(" len:%d size:%d\n", len, mp.size());
cache.free(a);
mp[h] = null;
}
return ans;
}
static class Cache {
Deque<int[]> free = new LinkedList<>();
public int[] allocate() {
if (free.isEmpty()) {
int[] arr = new int[650];
return arr;
} else {
int[] arr = free.poll();
Arrays.fill(arr, 0);
return arr;
}
}
public void free(int[] arr) {
free.addFirst(arr);
}
}
// Time limit exceeded on test 6
// 200000 1
// 463 msec
static int[] solve(int n, int k) {
// dp[v] is qualified ways to reach v after current steps
// use int[] instead of long reduced tiem from 463 to 422 msec
int[] curr = new int[n + 1];
int[] next = new int[n + 1];
curr[0] = 1;
// System.out.format(" 1 curr:%s\n", Arrays.toString(curr));
int b = 0;
int[] ans = new int[n];
for (int s = 0; s < 1000; s++) {
while (b <= n && curr[b] == 0) {
b++;
}
if (b > n) {
break;
}
int d = k + s;
// consider d modular classes
// b b+d b+2d ...
// b+1 b+d+1 b+2d+1
// ...
// b+d-1 b+d+d-1
for (int j = 0; j < d; j++) {
if (b + j > n) {
break;
}
// b+j b+d+j ... b+(m-1)d + j
int idx = b + j;
int sum = curr[idx];
while (idx + d <= n) {
idx += d;
// contribute sum to next[idx]
next[idx] = (next[idx] + sum) % MOD;
sum = (sum + curr[idx]) % MOD;
}
}
b += d;
Arrays.fill(curr, 0);
int[] t = curr;
curr = next;
next = t;
//System.out.format(" d:%d curr:%s\n", d, Arrays.toString(curr));
// merge here is faster (466 vs 549 msec) than update ans[idx-1] above
merge(curr, ans, b-1);
}
return ans;
}
static void merge(int[] curr, int[] ans, int b) {
int n = ans.length;
for (int i = b; i < n; i++) {
ans[i] = (ans[i] + curr[i+1]) % MOD;
}
}
static boolean test = false;
static void doTest() {
if (!test) {
return;
}
long t0 = System.currentTimeMillis();
// output(solve(10,2));
// output(solve(25252, 11));
// output(solve(30, 1));
output(solve(200000, 1));
System.out.format("%d msec\n", System.currentTimeMillis() - t0);
System.exit(0);
}
public static void main(String[] args) {
doTest();
MyScanner in = new MyScanner();
int n = in.nextInt();
int k = in.nextInt();
int[] ans = solve(n, k);
output(ans);
}
static void output(int[] a) {
StringBuilder sb = new StringBuilder();
for (int v : a) {
sb.append(v);
sb.append(' ');
if (sb.length() > 4000) {
System.out.print(sb.toString());
sb.setLength(0);
}
}
System.out.println(sb.toString());
}
static void myAssert(boolean cond) {
if (!cond) {
throw new RuntimeException("Unexpected");
}
}
static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
try {
final String USERDIR = System.getProperty("user.dir");
String cname = MethodHandles.lookup().lookupClass().getCanonicalName().replace(".MyScanner", "");
cname = cname.lastIndexOf('.') > 0 ? cname.substring(cname.lastIndexOf('.') + 1) : cname;
final File fin = new File(USERDIR + "/io/c" + cname.substring(1,5) + "/" + cname + ".in");
br = new BufferedReader(new InputStreamReader(fin.exists()
? new FileInputStream(fin) : System.in));
} catch (Exception e) {
br = new BufferedReader(new InputStreamReader(System.in));
}
}
public String next() {
try {
while (st == null || !st.hasMoreElements()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 12938dee843b02a652353a339042bce0 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
import static java.lang.System.out;
public class Main2 {
public static void main(String[] args)throws IOException{
var solver = new Main2();
solver.solve();
}
final int MOD = 998244353;
int add(long x, long y){
return (int)(x+y) % MOD;
}
void solve() throws IOException{
var reader = new BufferedReader(new InputStreamReader(System.in));
String line = reader.readLine();
StringTokenizer st = new StringTokenizer(line);
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
final int M = 640;
var dp = new int[2][n+10];
var suff = new int[k+M];
int c = 0;
for(int moves = M-1; moves >= 0; --moves){
int mm = k + moves;
Arrays.fill(suff, 0, mm, 0);
Arrays.fill(dp[c], 0);
suff[(n+1)%mm] = 1;
for(int i = n; i >= 1; --i){
if(i + mm <= n+1){
dp[c][i] = add(dp[c][i], suff[(i+mm)%mm]);
}
suff[i%mm] = add(suff[i%mm], dp[c^1][i]);
}
c ^= 1;
}
var sb = new StringBuilder();
for(int i = n; i >= 1; --i){
sb.append(dp[c ^ 1][i]).append(" ");
}
out.println(sb.toString());
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | ccc683b013752d1c87ea775a0e814b64 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.*;
import java.io.*;
public class D {
static class Scan {
private byte[] buf=new byte[1024];
private int index;
private InputStream in;
private int total;
public Scan()
{
in=System.in;
}
public int scan()throws IOException
{
if(total<0)
throw new InputMismatchException();
if(index>=total)
{
index=0;
total=in.read(buf);
if(total<=0)
return -1;
}
return buf[index++];
}
public int scanInt()throws IOException
{
int integer=0;
int n=scan();
while(isWhiteSpace(n))
n=scan();
int neg=1;
if(n=='-')
{
neg=-1;
n=scan();
}
while(!isWhiteSpace(n))
{
if(n>='0'&&n<='9')
{
integer*=10;
integer+=n-'0';
n=scan();
}
else throw new InputMismatchException();
}
return neg*integer;
}
public double scanDouble()throws IOException
{
double doub=0;
int n=scan();
while(isWhiteSpace(n))
n=scan();
int neg=1;
if(n=='-')
{
neg=-1;
n=scan();
}
while(!isWhiteSpace(n)&&n!='.')
{
if(n>='0'&&n<='9')
{
doub*=10;
doub+=n-'0';
n=scan();
}
else throw new InputMismatchException();
}
if(n=='.')
{
n=scan();
double temp=1;
while(!isWhiteSpace(n))
{
if(n>='0'&&n<='9')
{
temp/=10;
doub+=(n-'0')*temp;
n=scan();
}
else throw new InputMismatchException();
}
}
return doub*neg;
}
public String scanString()throws IOException
{
StringBuilder sb=new StringBuilder();
int n=scan();
while(isWhiteSpace(n))
n=scan();
while(!isWhiteSpace(n))
{
sb.append((char)n);
n=scan();
}
return sb.toString();
}
private boolean isWhiteSpace(int n)
{
if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
return true;
return false;
}
}
public static void sort(int arr[],int l,int r) { //sort(arr,0,n-1);
if(l==r) {
return;
}
int mid=(l+r)/2;
sort(arr,l,mid);
sort(arr,mid+1,r);
merge(arr,l,mid,mid+1,r);
}
public static void merge(int arr[],int l1,int r1,int l2,int r2) {
int tmp[]=new int[r2-l1+1];
int indx1=l1,indx2=l2;
//sorting the two halves using a tmp array
for(int i=0;i<tmp.length;i++) {
if(indx1>r1) {
tmp[i]=arr[indx2];
indx2++;
continue;
}
if(indx2>r2) {
tmp[i]=arr[indx1];
indx1++;
continue;
}
if(arr[indx1]<arr[indx2]) {
tmp[i]=arr[indx1];
indx1++;
continue;
}
tmp[i]=arr[indx2];
indx2++;
}
//Copying the elements of tmp into the main array
for(int i=0,j=l1;i<tmp.length;i++,j++) {
arr[j]=tmp[i];
}
}
public static void sort(long arr[],int l,int r) { //sort(arr,0,n-1);
if(l==r) {
return;
}
int mid=(l+r)/2;
sort(arr,l,mid);
sort(arr,mid+1,r);
merge(arr,l,mid,mid+1,r);
}
public static void merge(long arr[],int l1,int r1,int l2,int r2) {
long tmp[]=new long[r2-l1+1];
int indx1=l1,indx2=l2;
//sorting the two halves using a tmp array
for(int i=0;i<tmp.length;i++) {
if(indx1>r1) {
tmp[i]=arr[indx2];
indx2++;
continue;
}
if(indx2>r2) {
tmp[i]=arr[indx1];
indx1++;
continue;
}
if(arr[indx1]<arr[indx2]) {
tmp[i]=arr[indx1];
indx1++;
continue;
}
tmp[i]=arr[indx2];
indx2++;
}
//Copying the elements of tmp into the main array
for(int i=0,j=l1;i<tmp.length;i++,j++) {
arr[j]=tmp[i];
}
}
static int k,mod;
public static void main(String args[]) throws IOException {
Scan input=new Scan();
StringBuilder ans=new StringBuilder("");
int test=1;
for(int tt=1;tt<=test;tt++) {
int n=input.scanInt();
k=input.scanInt();
mod=998244353;
int arr[]=solve1(n);
for(int i=1;i<arr.length;i++) {
ans.append(arr[i]+" ");
}
ans.append("\n");
}
System.out.print(ans);
}
public static int[] solve1(int n) {
int sum[]=new int[n+1];
int arr[][]=new int[2][n+1];
int prefix[][]=new int[2][n+1];
int curr=0,prev=-1;
for(int i=0;i<650;i++) {
for(int j=1;j<arr[0].length;j++) {
if(i==0) {
if(j%k==0) {
arr[curr][j]=1;
}
prefix[curr][j]=arr[curr][j]+((j-(k+i+1)>=0)?prefix[curr][j-((k+i+1))]:0);
prefix[curr][j]%=mod;
sum[j]+=arr[curr][j];
sum[j]%=mod;
continue;
}
arr[curr][j]=(j-(k+i)>=0)?prefix[prev][j-(k+i)]:0;
prefix[curr][j]=arr[curr][j]+((j-(k+i+1)>=0)?prefix[curr][j-((k+i+1))]:0);
prefix[curr][j]%=mod;
sum[j]+=arr[curr][j];
sum[j]%=mod;
}
curr++;
prev++;
curr%=2;
prev%=2;
}
return sum;
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | e762c5700a8cbd73fe31d914598e9d26 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class D {
static int mod=998244353;
public static void main(String[] args) throws IOException {
Scanner stdin=new Scanner(System.in);
int n=stdin.nextInt();
int k=stdin.nextInt();
int kmax;
int bruhMoment=0;
for (kmax=k;bruhMoment<n;kmax++) bruhMoment += kmax;
kmax--;
int[] dp=new int[n+1];
int[] pre=new int[n+1];
dp[k]=1;
pre[k]=1;
int[] ans=new int[n+1];
ans[k]++;
for (int i=k+1;i<=n;i++) {
if (i%k==0) dp[i]=1;
pre[i]=(pre[i-(k+1)]+dp[i])%mod;
ans[i] = (ans[i]+dp[i])%mod;
}
for (int i=k+1;i<=kmax;i++) {
//int[] newPre=new int[n+1];
int kIdx=i-k;
for (int j=i+1;j<=n;j++) {
dp[j] = pre[j-(i)] % mod;
//newPre[j] = (newPre[j-(i+1)]+dp[j]) % mod;
ans[j]=(ans[j]+dp[j])%mod;
}
for (int j=0;j<=i;j++) pre[j]=0;
for (int j=i+1;j<=n;j++) pre[j]=(pre[j-(i+1)]+dp[j])%mod;
//pre=newPre;
}
StringBuilder out=new StringBuilder();
for (int i=1;i<=n;i++) {
out.append(ans[i]);
out.append(' ');
}
System.out.println(out);
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 0dfab78ff133976a642ca0909fb413bc | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | // Problem: D. Chip Move
// Contest: Codeforces - Educational Codeforces Round 133 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1716/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
import java.io.*;
import java.util.*;
public class Main {
static IntReader in;
static FastWriter out;
static String INPUT = "";
static final int N = 200010, MOD = 998244353, M = 700;
static int[] tmp = new int[N], pre = new int[N], res = new int[N];
static int n, k;
static void solve() {
n = ni();
k = ni();
// 一开始位于0处,方案数为1
pre[0] = 1;
// 模拟每一轮
for (int t = k, c = 1; t <= n && c <= M; t++, c++) {
// 枚举可能的起点
for (int st = 0; st < t; st++) {
// 前缀和加速计算
int s = 0;
for (int i = st; i <= n; i += t) {
// 计算当前轮
tmp[i] += s;
if (tmp[i] >= MOD) tmp[i] -= MOD;
// 累计方案数
s += pre[i];
if (s >= MOD) s -= MOD;
}
}
boolean flag = false;
for (int i = 0; i <= n; i++) {
pre[i] = tmp[i];
res[i] += tmp[i];
if (res[i] >= MOD) res[i] -= MOD;
tmp[i] = 0;
if (pre[i] > 0) flag = true;
}
if (!flag) break;
}
for (int i = 1; i <= n; i++)
out.print(res[i] + " ");
}
public static void main(String[] args) throws Exception {
in = INPUT.isEmpty() ? new IntReader(System.in) : new IntReader(new ByteArrayInputStream(INPUT.getBytes()));
out = new FastWriter(System.out);
solve();
out.flush();
}
public static class IntReader {
private InputStream is;
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
public IntReader(InputStream is) {
this.is = is;
}
private int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
private double nd() {
return Double.parseDouble(ns());
}
private char nc() {
return (char) skip();
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private int ni() {
return (int) nl();
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
}
public static class FastWriter {
private static final int BUF_SIZE = 1 << 13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter() {
out = null;
}
public FastWriter(OutputStream os) {
this.out = os;
}
public FastWriter(String path) {
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b) {
buf[ptr++] = b;
if (ptr == BUF_SIZE) innerflush();
return this;
}
public FastWriter write(char c) {
return write((byte) c);
}
public FastWriter write(char[] s) {
for (char c : s) {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE) innerflush();
}
return this;
}
public FastWriter write(String s) {
s.chars().forEach(c -> {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE) innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000) return 10;
if (l >= 100000000) return 9;
if (l >= 10000000) return 8;
if (l >= 1000000) return 7;
if (l >= 100000) return 6;
if (l >= 10000) return 5;
if (l >= 1000) return 4;
if (l >= 100) return 3;
if (l >= 10) return 2;
return 1;
}
public FastWriter write(int x) {
if (x == Integer.MIN_VALUE) {
return write((long) x);
}
if (ptr + 12 >= BUF_SIZE) innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L) return 19;
if (l >= 100000000000000000L) return 18;
if (l >= 10000000000000000L) return 17;
if (l >= 1000000000000000L) return 16;
if (l >= 100000000000000L) return 15;
if (l >= 10000000000000L) return 14;
if (l >= 1000000000000L) return 13;
if (l >= 100000000000L) return 12;
if (l >= 10000000000L) return 11;
if (l >= 1000000000L) return 10;
if (l >= 100000000L) return 9;
if (l >= 10000000L) return 8;
if (l >= 1000000L) return 7;
if (l >= 100000L) return 6;
if (l >= 10000L) return 5;
if (l >= 1000L) return 4;
if (l >= 100L) return 3;
if (l >= 10L) return 2;
return 1;
}
public FastWriter write(long x) {
if (x == Long.MIN_VALUE) {
return write("" + x);
}
if (ptr + 21 >= BUF_SIZE) innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision) {
if (x < 0) {
write('-');
x = -x;
}
x += Math.pow(10, -precision) / 2;
// if(x < 0){ x = 0; }
write((long) x).write(".");
x -= (long) x;
for (int i = 0; i < precision; i++) {
x *= 10;
write((char) ('0' + (int) x));
x -= (int) x;
}
return this;
}
public FastWriter writeln(char c) {
return write(c).writeln();
}
public FastWriter writeln(int x) {
return write(x).writeln();
}
public FastWriter writeln(long x) {
return write(x).writeln();
}
public FastWriter writeln(double x, int precision) {
return write(x, precision).writeln();
}
public FastWriter write(int... xs) {
boolean first = true;
for (int x : xs) {
if (!first) write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs) {
boolean first = true;
for (long x : xs) {
if (!first) write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln() {
return write((byte) '\n');
}
public FastWriter writeln(int... xs) {
return write(xs).writeln();
}
public FastWriter writeln(long... xs) {
return write(xs).writeln();
}
public FastWriter writeln(char[] line) {
return write(line).writeln();
}
public FastWriter writeln(char[]... map) {
for (char[] line : map) write(line).writeln();
return this;
}
public FastWriter writeln(String s) {
return write(s).writeln();
}
private void innerflush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush() {
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) {
return write(b);
}
public FastWriter print(char c) {
return write(c);
}
public FastWriter print(char[] s) {
return write(s);
}
public FastWriter print(String s) {
return write(s);
}
public FastWriter print(int x) {
return write(x);
}
public FastWriter print(long x) {
return write(x);
}
public FastWriter print(double x, int precision) {
return write(x, precision);
}
public FastWriter println(char c) {
return writeln(c);
}
public FastWriter println(int x) {
return writeln(x);
}
public FastWriter println(long x) {
return writeln(x);
}
public FastWriter println(double x, int precision) {
return writeln(x, precision);
}
public FastWriter print(int... xs) {
return write(xs);
}
public FastWriter print(long... xs) {
return write(xs);
}
public FastWriter println(int... xs) {
return writeln(xs);
}
public FastWriter println(long... xs) {
return writeln(xs);
}
public FastWriter println(char[] line) {
return writeln(line);
}
public FastWriter println(char[]... map) {
return writeln(map);
}
public FastWriter println(String s) {
return writeln(s);
}
public FastWriter println() {
return writeln();
}
}
static int ni() {
return in.ni();
}
static long nl() {
return in.nl();
}
static String ns() {
return in.ns();
}
static double nd() {
return Double.parseDouble(in.ns());
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | ae029467f433dc5367e4283fe88716cc | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | // Problem: D. Chip Move
// Contest: Codeforces - Educational Codeforces Round 133 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1716/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
import java.io.*;
import java.util.*;
public class Main {
static IntReader in;
static FastWriter out;
static String INPUT = "";
static final int N = 200010, MOD = 998244353, M = 700;
static int[] tmp = new int[N], pre = new int[N];
static int[] res = new int[N];
static int n, k;
static void solve() {
n = ni();
k = ni();
pre[0] = 1;
for (int t = k, cnt = 1; t <= n && cnt <= M; cnt++, t++) {
int flag = 0;
for (int st = 0; st < t; st++) {
int sum = 0;
for (int i = st; i <= n; i += t) {
tmp[i] += sum;
if (tmp[i] >= MOD) tmp[i] -= MOD;
sum += pre[i];
if (sum >= MOD) sum -= MOD;
}
}
for (int i = 0; i <= n; i++) {
pre[i] = tmp[i];
res[i] += tmp[i];
if (res[i] >= MOD) res[i] -= MOD;
tmp[i] = 0;
if (pre[i] > 0) flag = 1;
}
if (flag == 0) break;
}
for (int i = 1; i <= n; i++) {
out.print(res[i] + " ");
}
}
public static void main(String[] args) throws Exception {
in = INPUT.isEmpty() ? new IntReader(System.in) : new IntReader(new ByteArrayInputStream(INPUT.getBytes()));
out = new FastWriter(System.out);
solve();
out.flush();
}
public static class IntReader {
private InputStream is;
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
public IntReader(InputStream is) {
this.is = is;
}
private int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
private double nd() {
return Double.parseDouble(ns());
}
private char nc() {
return (char) skip();
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private int ni() {
return (int) nl();
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
}
public static class FastWriter {
private static final int BUF_SIZE = 1 << 13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter() {
out = null;
}
public FastWriter(OutputStream os) {
this.out = os;
}
public FastWriter(String path) {
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b) {
buf[ptr++] = b;
if (ptr == BUF_SIZE) innerflush();
return this;
}
public FastWriter write(char c) {
return write((byte) c);
}
public FastWriter write(char[] s) {
for (char c : s) {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE) innerflush();
}
return this;
}
public FastWriter write(String s) {
s.chars().forEach(c -> {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE) innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000) return 10;
if (l >= 100000000) return 9;
if (l >= 10000000) return 8;
if (l >= 1000000) return 7;
if (l >= 100000) return 6;
if (l >= 10000) return 5;
if (l >= 1000) return 4;
if (l >= 100) return 3;
if (l >= 10) return 2;
return 1;
}
public FastWriter write(int x) {
if (x == Integer.MIN_VALUE) {
return write((long) x);
}
if (ptr + 12 >= BUF_SIZE) innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L) return 19;
if (l >= 100000000000000000L) return 18;
if (l >= 10000000000000000L) return 17;
if (l >= 1000000000000000L) return 16;
if (l >= 100000000000000L) return 15;
if (l >= 10000000000000L) return 14;
if (l >= 1000000000000L) return 13;
if (l >= 100000000000L) return 12;
if (l >= 10000000000L) return 11;
if (l >= 1000000000L) return 10;
if (l >= 100000000L) return 9;
if (l >= 10000000L) return 8;
if (l >= 1000000L) return 7;
if (l >= 100000L) return 6;
if (l >= 10000L) return 5;
if (l >= 1000L) return 4;
if (l >= 100L) return 3;
if (l >= 10L) return 2;
return 1;
}
public FastWriter write(long x) {
if (x == Long.MIN_VALUE) {
return write("" + x);
}
if (ptr + 21 >= BUF_SIZE) innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision) {
if (x < 0) {
write('-');
x = -x;
}
x += Math.pow(10, -precision) / 2;
// if(x < 0){ x = 0; }
write((long) x).write(".");
x -= (long) x;
for (int i = 0; i < precision; i++) {
x *= 10;
write((char) ('0' + (int) x));
x -= (int) x;
}
return this;
}
public FastWriter writeln(char c) {
return write(c).writeln();
}
public FastWriter writeln(int x) {
return write(x).writeln();
}
public FastWriter writeln(long x) {
return write(x).writeln();
}
public FastWriter writeln(double x, int precision) {
return write(x, precision).writeln();
}
public FastWriter write(int... xs) {
boolean first = true;
for (int x : xs) {
if (!first) write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs) {
boolean first = true;
for (long x : xs) {
if (!first) write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln() {
return write((byte) '\n');
}
public FastWriter writeln(int... xs) {
return write(xs).writeln();
}
public FastWriter writeln(long... xs) {
return write(xs).writeln();
}
public FastWriter writeln(char[] line) {
return write(line).writeln();
}
public FastWriter writeln(char[]... map) {
for (char[] line : map) write(line).writeln();
return this;
}
public FastWriter writeln(String s) {
return write(s).writeln();
}
private void innerflush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush() {
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) {
return write(b);
}
public FastWriter print(char c) {
return write(c);
}
public FastWriter print(char[] s) {
return write(s);
}
public FastWriter print(String s) {
return write(s);
}
public FastWriter print(int x) {
return write(x);
}
public FastWriter print(long x) {
return write(x);
}
public FastWriter print(double x, int precision) {
return write(x, precision);
}
public FastWriter println(char c) {
return writeln(c);
}
public FastWriter println(int x) {
return writeln(x);
}
public FastWriter println(long x) {
return writeln(x);
}
public FastWriter println(double x, int precision) {
return writeln(x, precision);
}
public FastWriter print(int... xs) {
return write(xs);
}
public FastWriter print(long... xs) {
return write(xs);
}
public FastWriter println(int... xs) {
return writeln(xs);
}
public FastWriter println(long... xs) {
return writeln(xs);
}
public FastWriter println(char[] line) {
return writeln(line);
}
public FastWriter println(char[]... map) {
return writeln(map);
}
public FastWriter println(String s) {
return writeln(s);
}
public FastWriter println() {
return writeln();
}
}
static int ni() {
return in.ni();
}
static long nl() {
return in.nl();
}
static String ns() {
return in.ns();
}
static double nd() {
return Double.parseDouble(in.ns());
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 30f43bce66a330546f1d94339af64795 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.Thread.State;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.lang.reflect.Field;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
public class Main {
static final long MOD1=1000000007;
static final int MOD=998244353;
static final int NTT_MOD1 = 998244353;
static final int NTT_MOD2 = 1053818881;
static final int NTT_MOD3 = 1004535809;
static long MAX = 1000000000000000000l;
public static void main(String[] args){
PrintWriter out = new PrintWriter(System.out);
InputReader sc=new InputReader(System.in);
FastPrintStream fw = new FastPrintStream();
int n = sc.nextInt();
int k = sc.nextInt();
int[] ans = new int[n];
int sum = 0;
int[] dp = new int[n + 1];
dp[0] = 1;
for (int i = k; i <= n; i++) {
sum += i;
if(sum > n) break;
int[] cum = new int[n + 1];
for (int j = sum; j <= n; j++) {
int val = modadd(cum[j - i], dp[j - i]);
cum[j] = val;
ans[j-1] = modadd(ans[j-1], val);
}
dp = Arrays.copyOf(cum, n);
}
for (int i = 0; i < n; i++) {
out.println(ans[i]);
}
out.flush();
}
static int modadd(int a, int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
static class InputReader {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public InputReader(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public double[] nextDoubleArray(int n) {
double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = nextDouble();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[][] nextCharMap(int n, int m) {
char[][] map = new char[n][m];
for (int i = 0; i < n; i++)
map[i] = next().toCharArray();
return map;
}
}
}
class FastPrintStream implements AutoCloseable {
private static final int INT_MAX_LEN = 11;
private static final int LONG_MAX_LEN = 20;
private int precision = 9;
private static final int BUF_SIZE = 1 << 14;
private static final int BUF_SIZE_MINUS_INT_MAX_LEN = BUF_SIZE - INT_MAX_LEN;
private static final int BUF_SIZE_MINUS_LONG_MAX_LEN = BUF_SIZE - LONG_MAX_LEN;
private final byte[] buf = new byte[BUF_SIZE];
private int ptr = 0;
private final Field strField;
private final CharsetEncoder encoder;
private final OutputStream out;
public FastPrintStream(OutputStream out) {
this.out = out;
Field f;
try {
f = String.class.getDeclaredField("value");
f.setAccessible(true);
} catch (NoSuchFieldException | SecurityException e) {
f = null;
}
this.strField = f;
this.encoder = StandardCharsets.US_ASCII.newEncoder();
}
public FastPrintStream(File file) throws IOException {
this(new FileOutputStream(file));
}
public FastPrintStream(String filename) throws IOException {
this(new File(filename));
}
public FastPrintStream() {
this(new FileOutputStream(FileDescriptor.out));
}
public FastPrintStream println() {
if (ptr == BUF_SIZE) internalFlush();
buf[ptr++] = (byte) '\n';
return this;
}
public FastPrintStream println(Object o) {
return print(o).println();
}
public FastPrintStream println(String s) {
return print(s).println();
}
public FastPrintStream println(char[] s) {
return print(s).println();
}
public FastPrintStream println(char c) {
return print(c).println();
}
public FastPrintStream println(int x) {
return print(x).println();
}
public FastPrintStream println(long x) {
return print(x).println();
}
public FastPrintStream println(double d, int precision) {
return print(d, precision).println();
}
public FastPrintStream println(double d) {
return print(d).println();
}
private FastPrintStream print(byte[] bytes) {
int n = bytes.length;
if (ptr + n > BUF_SIZE) {
internalFlush();
try {
out.write(bytes);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
} else {
System.arraycopy(bytes, 0, buf, ptr, n);
ptr += n;
}
return this;
}
public FastPrintStream print(Object o) {
return print(o.toString());
}
public FastPrintStream print(String s) {
if (strField == null) {
return print(s.getBytes());
} else {
try {
Object value = strField.get(s);
if (value instanceof byte[]) {
return print((byte[]) value);
} else {
return print((char[]) value);
}
} catch (IllegalAccessException e) {
return print(s.getBytes());
}
}
}
public FastPrintStream print(char[] s) {
try {
return print(encoder.encode(CharBuffer.wrap(s)).array());
} catch (CharacterCodingException e) {
byte[] bytes = new byte[s.length];
for (int i = 0; i < s.length; i++) {
bytes[i] = (byte) s[i];
}
return print(bytes);
}
}
public FastPrintStream print(char c) {
if (ptr == BUF_SIZE) internalFlush();
buf[ptr++] = (byte) c;
return this;
}
public FastPrintStream print(int x) {
if (ptr > BUF_SIZE_MINUS_INT_MAX_LEN) internalFlush();
if (-10 < x && x < 10) {
if (x < 0) {
buf[ptr++] = '-';
x = -x;
}
buf[ptr++] = (byte) ('0' + x);
return this;
}
int d;
if (x < 0) {
if (x == Integer.MIN_VALUE) {
buf[ptr++] = '-'; buf[ptr++] = '2'; buf[ptr++] = '1'; buf[ptr++] = '4';
buf[ptr++] = '7'; buf[ptr++] = '4'; buf[ptr++] = '8'; buf[ptr++] = '3';
buf[ptr++] = '6'; buf[ptr++] = '4'; buf[ptr++] = '8';
return this;
}
d = len(x = -x);
buf[ptr++] = '-';
} else {
d = len(x);
}
int j = ptr += d;
while (x > 0) {
buf[--j] = (byte) ('0' + (x % 10));
x /= 10;
}
return this;
}
public FastPrintStream print(long x) {
if ((int) x == x) return print((int) x);
if (ptr > BUF_SIZE_MINUS_LONG_MAX_LEN) internalFlush();
int d;
if (x < 0) {
if (x == Long.MIN_VALUE) {
buf[ptr++] = '-'; buf[ptr++] = '9'; buf[ptr++] = '2'; buf[ptr++] = '2';
buf[ptr++] = '3'; buf[ptr++] = '3'; buf[ptr++] = '7'; buf[ptr++] = '2';
buf[ptr++] = '0'; buf[ptr++] = '3'; buf[ptr++] = '6'; buf[ptr++] = '8';
buf[ptr++] = '5'; buf[ptr++] = '4'; buf[ptr++] = '7'; buf[ptr++] = '7';
buf[ptr++] = '5'; buf[ptr++] = '8'; buf[ptr++] = '0'; buf[ptr++] = '8';
return this;
}
d = len(x = -x);
buf[ptr++] = '-';
} else {
d = len(x);
}
int j = ptr += d;
while (x > 0) {
buf[--j] = (byte) ('0' + (x % 10));
x /= 10;
}
return this;
}
public FastPrintStream print(double d, int precision) {
if (d < 0) {
print('-');
d = -d;
}
d += Math.pow(10, -precision) / 2;
print((long) d).print('.');
d -= (long) d;
for(int i = 0; i < precision; i++){
d *= 10;
print((int) d);
d -= (int) d;
}
return this;
}
public FastPrintStream print(double d) {
return print(d, precision);
}
public void setPrecision(int precision) {
this.precision = precision;
}
private void internalFlush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public void flush() {
try {
out.write(buf, 0, ptr);
out.flush();
ptr = 0;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public void close() {
try {
out.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
private static int len(int x) {
return
x >= 1000000000 ? 10 :
x >= 100000000 ? 9 :
x >= 10000000 ? 8 :
x >= 1000000 ? 7 :
x >= 100000 ? 6 :
x >= 10000 ? 5 :
x >= 1000 ? 4 :
x >= 100 ? 3 :
x >= 10 ? 2 : 1;
}
private static int len(long x) {
return
x >= 1000000000000000000L ? 19 :
x >= 100000000000000000L ? 18 :
x >= 10000000000000000L ? 17 :
x >= 1000000000000000L ? 16 :
x >= 100000000000000L ? 15 :
x >= 10000000000000L ? 14 :
x >= 1000000000000L ? 13 :
x >= 100000000000L ? 12 :
x >= 10000000000L ? 11 : 10;
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 9be5dac4e7dee435660c8b86e38bbca0 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.Thread.State;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.lang.reflect.Field;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
public class Main {
static final long MOD1=1000000007;
static final int MOD=998244353;
static final int NTT_MOD1 = 998244353;
static final int NTT_MOD2 = 1053818881;
static final int NTT_MOD3 = 1004535809;
static long MAX = 1000000000000000000l;
public static void main(String[] args){
PrintWriter out = new PrintWriter(System.out);
InputReader sc=new InputReader(System.in);
FastPrintStream fw = new FastPrintStream();
int n = sc.nextInt();
int k = sc.nextInt();
int[] ans = new int[n];
int sum = 0;
int[] dp = new int[n + 1];
dp[0] = 1;
for (int i = k; i <= n; i++) {
sum += i;
if(sum > n) break;
int[] cum = new int[n + 1];
for (int j = sum; j <= n; j++) {
int val = modadd(cum[j - i], dp[j - i]);
cum[j] = val;
ans[j-1] = modadd(ans[j-1], val);
}
dp = Arrays.copyOf(cum, n);
}
for (int i = 0; i < n; i++) {
fw.println(ans[i]);
}
fw.flush();
}
static int modadd(int a, int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
static class InputReader {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public InputReader(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public double[] nextDoubleArray(int n) {
double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = nextDouble();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[][] nextCharMap(int n, int m) {
char[][] map = new char[n][m];
for (int i = 0; i < n; i++)
map[i] = next().toCharArray();
return map;
}
}
}
class FastPrintStream implements AutoCloseable {
private static final int INT_MAX_LEN = 11;
private static final int LONG_MAX_LEN = 20;
private int precision = 9;
private static final int BUF_SIZE = 1 << 14;
private static final int BUF_SIZE_MINUS_INT_MAX_LEN = BUF_SIZE - INT_MAX_LEN;
private static final int BUF_SIZE_MINUS_LONG_MAX_LEN = BUF_SIZE - LONG_MAX_LEN;
private final byte[] buf = new byte[BUF_SIZE];
private int ptr = 0;
private final Field strField;
private final CharsetEncoder encoder;
private final OutputStream out;
public FastPrintStream(OutputStream out) {
this.out = out;
Field f;
try {
f = String.class.getDeclaredField("value");
f.setAccessible(true);
} catch (NoSuchFieldException | SecurityException e) {
f = null;
}
this.strField = f;
this.encoder = StandardCharsets.US_ASCII.newEncoder();
}
public FastPrintStream(File file) throws IOException {
this(new FileOutputStream(file));
}
public FastPrintStream(String filename) throws IOException {
this(new File(filename));
}
public FastPrintStream() {
this(new FileOutputStream(FileDescriptor.out));
}
public FastPrintStream println() {
if (ptr == BUF_SIZE) internalFlush();
buf[ptr++] = (byte) '\n';
return this;
}
public FastPrintStream println(Object o) {
return print(o).println();
}
public FastPrintStream println(String s) {
return print(s).println();
}
public FastPrintStream println(char[] s) {
return print(s).println();
}
public FastPrintStream println(char c) {
return print(c).println();
}
public FastPrintStream println(int x) {
return print(x).println();
}
public FastPrintStream println(long x) {
return print(x).println();
}
public FastPrintStream println(double d, int precision) {
return print(d, precision).println();
}
public FastPrintStream println(double d) {
return print(d).println();
}
private FastPrintStream print(byte[] bytes) {
int n = bytes.length;
if (ptr + n > BUF_SIZE) {
internalFlush();
try {
out.write(bytes);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
} else {
System.arraycopy(bytes, 0, buf, ptr, n);
ptr += n;
}
return this;
}
public FastPrintStream print(Object o) {
return print(o.toString());
}
public FastPrintStream print(String s) {
if (strField == null) {
return print(s.getBytes());
} else {
try {
Object value = strField.get(s);
if (value instanceof byte[]) {
return print((byte[]) value);
} else {
return print((char[]) value);
}
} catch (IllegalAccessException e) {
return print(s.getBytes());
}
}
}
public FastPrintStream print(char[] s) {
try {
return print(encoder.encode(CharBuffer.wrap(s)).array());
} catch (CharacterCodingException e) {
byte[] bytes = new byte[s.length];
for (int i = 0; i < s.length; i++) {
bytes[i] = (byte) s[i];
}
return print(bytes);
}
}
public FastPrintStream print(char c) {
if (ptr == BUF_SIZE) internalFlush();
buf[ptr++] = (byte) c;
return this;
}
public FastPrintStream print(int x) {
if (ptr > BUF_SIZE_MINUS_INT_MAX_LEN) internalFlush();
if (-10 < x && x < 10) {
if (x < 0) {
buf[ptr++] = '-';
x = -x;
}
buf[ptr++] = (byte) ('0' + x);
return this;
}
int d;
if (x < 0) {
if (x == Integer.MIN_VALUE) {
buf[ptr++] = '-'; buf[ptr++] = '2'; buf[ptr++] = '1'; buf[ptr++] = '4';
buf[ptr++] = '7'; buf[ptr++] = '4'; buf[ptr++] = '8'; buf[ptr++] = '3';
buf[ptr++] = '6'; buf[ptr++] = '4'; buf[ptr++] = '8';
return this;
}
d = len(x = -x);
buf[ptr++] = '-';
} else {
d = len(x);
}
int j = ptr += d;
while (x > 0) {
buf[--j] = (byte) ('0' + (x % 10));
x /= 10;
}
return this;
}
public FastPrintStream print(long x) {
if ((int) x == x) return print((int) x);
if (ptr > BUF_SIZE_MINUS_LONG_MAX_LEN) internalFlush();
int d;
if (x < 0) {
if (x == Long.MIN_VALUE) {
buf[ptr++] = '-'; buf[ptr++] = '9'; buf[ptr++] = '2'; buf[ptr++] = '2';
buf[ptr++] = '3'; buf[ptr++] = '3'; buf[ptr++] = '7'; buf[ptr++] = '2';
buf[ptr++] = '0'; buf[ptr++] = '3'; buf[ptr++] = '6'; buf[ptr++] = '8';
buf[ptr++] = '5'; buf[ptr++] = '4'; buf[ptr++] = '7'; buf[ptr++] = '7';
buf[ptr++] = '5'; buf[ptr++] = '8'; buf[ptr++] = '0'; buf[ptr++] = '8';
return this;
}
d = len(x = -x);
buf[ptr++] = '-';
} else {
d = len(x);
}
int j = ptr += d;
while (x > 0) {
buf[--j] = (byte) ('0' + (x % 10));
x /= 10;
}
return this;
}
public FastPrintStream print(double d, int precision) {
if (d < 0) {
print('-');
d = -d;
}
d += Math.pow(10, -precision) / 2;
print((long) d).print('.');
d -= (long) d;
for(int i = 0; i < precision; i++){
d *= 10;
print((int) d);
d -= (int) d;
}
return this;
}
public FastPrintStream print(double d) {
return print(d, precision);
}
public void setPrecision(int precision) {
this.precision = precision;
}
private void internalFlush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public void flush() {
try {
out.write(buf, 0, ptr);
out.flush();
ptr = 0;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public void close() {
try {
out.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
private static int len(int x) {
return
x >= 1000000000 ? 10 :
x >= 100000000 ? 9 :
x >= 10000000 ? 8 :
x >= 1000000 ? 7 :
x >= 100000 ? 6 :
x >= 10000 ? 5 :
x >= 1000 ? 4 :
x >= 100 ? 3 :
x >= 10 ? 2 : 1;
}
private static int len(long x) {
return
x >= 1000000000000000000L ? 19 :
x >= 100000000000000000L ? 18 :
x >= 10000000000000000L ? 17 :
x >= 1000000000000000L ? 16 :
x >= 100000000000000L ? 15 :
x >= 10000000000000L ? 14 :
x >= 1000000000000L ? 13 :
x >= 100000000000L ? 12 :
x >= 10000000000L ? 11 : 10;
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | a43c004b333d5e7988fa5288ace8dc1a | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.awt.SystemColor;
import java.io.*;
import java.util.*;
//import org.graalvm.compiler.core.common.Fields.ObjectTransformer;
import java.math.*;
import java.math.BigInteger;
public final class A
{
static PrintWriter out = new PrintWriter(System.out);
static StringBuilder ans=new StringBuilder();
static FastReader in=new FastReader();
static ArrayList<Integer> g[];
static long mod=998244353,INF=Long.MAX_VALUE;
static boolean set[];
static int max=0;
static int lca[][];
static int par[],col[],D[];
static long fact[];
static int size[],dp[][],countW[],countB[],N;
static long sum[],f[];
static long t[],max_depth[],seg[];
static boolean sep[],isWhite[];
static boolean marked[],visited[],recStack[];
static int segR[],segC[];
static HashMap<Integer,Integer> mp[];
public static void main(String args[])throws IOException
{
/*
* star,rope,TPST
* BS,LST,MS,MQ
*/
int N=i(),K=i();
long A[]=new long[N+1];
long dp[]=new long[N+1];
long last[]=new long[N+1];
for(int i=K; i<=N; i++)
{
if(i%K==0)A[i]=1;
last[i]=A[i];
if(i>=(K+1)) last[i]+=last[i-(1+K)];
}
int s=K;
for(int i=2; i<=650; i++)
{
int a=i+K-1;
s+=a;
if(s>N)break;
if(i%2==0)
{
for(int j=s; j<=N; j++)
{
dp[j]=last[j-a];
A[j]+=dp[j];
if(A[j]>=mod)A[j]-=mod;
if(j>=(s+a+1))dp[j]+=dp[j-(a+1)];
if(dp[j]>=mod)dp[j]-=mod;
}
}
else
{
for(int j=s; j<=N; j++)
{
last[j]=dp[j-a];
A[j]+=last[j];
if(A[j]>=mod)A[j]-=mod;
if(j>=(s+a+1))last[j]+=last[j-(a+1)];
if(last[j]>=mod)last[j]-=mod;
}
}
}
for(int i=1; i<=N; i++)
{
ans.append(A[i]+" ");
}
out.println(ans);
out.close();
}
public static long fx(int N,long y,int A[])
{
if(N==1)return A[0];
long max=0;
for(int i=0; i<N; i++)
{
int B[]=Arrays.copyOf(A, N);
for(int j=i; j<N-1; j++)
{
B[j]=B[j+1];
}
}
return max;
}
public static int lengthOfLIS(long[] A) {
int N=A.length;
long dp[]=new long[N+1];
Arrays.fill(dp,Integer.MAX_VALUE);
dp[0]=Integer.MIN_VALUE;
int max=1;
for(int i=0; i<N; i++)
{
int l=0,r=max; long a=A[i];
while(r-l>1)
{
int m=(l+r)/2;
if(dp[m]<a)l=m;
else r=m;
}
dp[l+1]=Math.min(dp[l+1],a);
max=Math.max(l+2,max);
}
return Math.max(max-1,1);
}
public static int[] f(int X[],int Y[],int Z[],long m,int M)
{
int N=X.length;
int A[]=new int[N];
for(int i=0; i<N; i++)
{
//can we make M+1?
//l=0
int l=0,r=M+5;
while(r-l>1)
{
int mm=(l+r)/2;
//minimum time to make mm items
//t items
int x=mm/Z[i];
int mt=(X[i]*Z[i])+Y[i];
mt*=x;
if(mm%Z[i]==0)
{
mt-=Y[i];
}
else
{
x=mm%Z[i];
mt+=(x*X[i]);
}
// System.out.println("for--> items "+mm+" "+mt+" --- "+x);
if(mt<=m)l=mm;
else r=mm;
}
A[i]=l;
}
return A;
}
public static int f(int i,int A[])
{
if(i+1==A.length)return Math.min(1,A[i]);
if(dp[i][A[i]]==0)
{
A[i+1]^=A[i];
int a=f(i+1,A);
A[i+1]^=A[i];
int b=f(i+1,A);
if(A[i]!=0)
{
a++;
b++;
}
dp[i][A[i]]= Math.min(a, b);
}
return dp[i][A[i]];
}
public static int f1(String text)
{
char X[]=text.toCharArray();
int N=X.length;
int f[]=new int[26];
for(char x:X)f[x-'a']++;
int s=0;
int m=1;
Arrays.sort(f);
// print(f);
for(int a=25; a>=0; a-- )
{
int i=f[a];
if(i!=0)
{
if(m<=9)
s+=i;
else if(m<=18)s+=(2*i);
else s+=(3*i);
m++;
}
}
return s;
}
static int f(int A[][])
{
int c=0;
int N=A.length,M=A[0].length;
int col[]=new int[M],row[]=new int[N];
for(int i=0; i<N; i++)
{
for(int j=0; j<M; j++)
{
if(A[i][j]==1)
{
col[j]++;
row[i]++;
}
}
}
for(int i=0; i<N; i++)
{
for(int j=0; j<M; j++)
{
int tot=N+M-1;
c=Math.max(c, (col[j]+row[i])*2-tot);
}
}
return c;
}
static int ttt=0;
static int ask(int a,int b)
{
out.println("? "+a+" "+b);
// out.println();
ttt++;
out.flush();
return i();
}
static int f(int l,int r,int A[])
{
if(l==r)
{
return A[1];
}
if(r-l==1)
{
int a=ask(A[l],A[r]);
if(a==1)return A[l];
else return A[r];
}
else
{
int j=0;
for(int i=1; i<=r; i+=4)
{
int a=ask(A[i],A[i+2]);
if(a==0)
{
a=ask(A[i+1],A[i+3]);
if(a==1)A[++j]=A[i+1];
else A[++j]=A[i+3];
}
else if(a==1)
{
// A[++j]=ask(A[i],A[i+3]);
a=ask(A[i],A[i+3]);
if(a==1)A[++j]=A[i];
else A[++j]=A[i+3];
}
else
{
// A[++j]=ask(A[i+1],A[i+2]);
a=ask(A[i+1],A[i+2]);
if(a==1)A[++j]=A[i+1];
else A[++j]=A[i+2];
}
}
r=j;
return f(l,r,A);
}
}
static int dff(int n,int p,long L[],long R[])
{
long s=0;
int cnt=0;
for(int c:g[n])
{
if(c!=p)
{
cnt+=dff(c,n,L,R);
s+=sum[c];
}
}
if(s<L[n])
{
cnt++;
sum[n]=R[n];
}
else
{
sum[n]=Math.min(s, R[n]);
}
return cnt;
}
static void calculatePre(long A[][],int N,int M)
{
for(int i=1; i<=N; i++)
{
for(int j=1; j<=M; j++)A[i][j]+=A[i][j-1];
}
for(int j=1; j<=M; j++)
{
for(int i=2; i<=N; i++)A[i][j]+=A[i-1][j];
}
}
static boolean equals(char X[],char Y[])
{
for(int i=0; i<X.length; i++)if(X[i]!=Y[i])return false;
return true;
}
static long nCr(long n,long r)
{
long s=0;
long c=n-r;
n=fact[(int)n];
r=fact[(int)r];
c=fact[(int)c];
r=pow(r,mod-2)%mod;
c=pow(c,mod-2)%mod;
s=(r*c)%mod;
s=(s*n)%mod;
return s%mod;
}
static boolean isValid(int x,int y,int N,int M)
{
if(x>=N || y>=M)return false;
if(x<0 || y<0)return false;
return true;
}
static int f2(int n,int p)
{
ArrayList<Integer> X=new ArrayList<>();
for(int c:g[n])
{
if(c!=p)
{
X.add(c);
}
}
// System.out.println("for--> "+n+" "+X);
if(X.size()==0)return 0;
if(X.size()==1)return size[n]-1;
int a=X.get(0),b=X.get(1);
// System.out.println("n--> "+n+" "+(size[a]+f2(b,n))+" "+(size[b]+f2(a,n)));
return Math.max(size[a]+f2(b,n), size[b]+f2(a,n));
// return 0;
}
static void f(int n,int p)
{
for(int c:g[n])
{
if(c!=p)
{
f(c,n);
size[n]+=size[c]+1;
}
}
// size[n]++;
}
static boolean isPower(long a,long b)
{
while(a%b==0)
{
}
return a==1;
}
static String rotate(String X,int K)
{
StringBuilder sb=new StringBuilder();
int N=X.length();
int k=K%N;
for(int i=N-k; i<N;i++)
{
sb.append(X.charAt(i));
}
for(int i=0; i<N-k; i++)
{
sb.append(X.charAt(i));
}
return sb.toString();
}
static int rounds(String X,String Y)
{
int n=Y.length();
for(int i=1; i<Y.length(); i++)
{
if(X.charAt(0)==Y.charAt(0) && X.substring(i,i+n).equals(Y))return i;
}
return Y.length();
}
static int index(ArrayList<Long> X,long x)
{
int l=-1,r=X.size();
while(r-l>1)
{
int m=(l+r)/2;
if(X.get(m)<=x)l=m;
else r=m;
}
return l+1;
}
static void swap(int i,int j,long A[][])
{
for(int row=0; row<A.length; row++)
{
long t=A[row][i];
A[row][i]=A[row][j];
A[row][j]=t;
}
}
static boolean isSorted(long A[])
{
for(int i=1; i<A.length; i++)if(A[i]<A[i-1])return false;
return true;
}
static void dfs(int node, int dp[],
boolean visited[],long A[],long a)
{
// Mark as visited
visited[node] = true;
// Traverse for all its children
for (int c:g[node])
{
// If not visited
if (A[c-1]<=a && !visited[c])
dfs(c, dp, visited,A,a);
// Store the max of the paths
dp[node] = Math.max(dp[node], 1 + dp[c]);
}
}
static int findLongestPath( int n,long A[],long a)
{
// Dp array
int[] dp = new int[n+1];
// Visited array to know if the node
// has been visited previously or not
boolean[] visited = new boolean[n + 1];
// Call DFS for every unvisited vertex
for (int i = 1; i <= n; i++)
{
if (A[i-1]<=a && !visited[i])
dfs(i, dp, visited,A,a);
}
int ans = 0;
// Traverse and find the maximum of all dp[i]
for (int i = 1; i <= n; i++)
{
ans = Math.max(ans, dp[i]);
}
return ans;
}
static boolean isCyclicUtil(int n, boolean[] visited,
boolean[] recStack,long A[],long a)
{
if (recStack[n])
return true;
if (visited[n])
return false;
visited[n] = true;
recStack[n] = true;
for (int c: g[n])
{
if(A[c-1]<=a )
{
if (isCyclicUtil(c, visited, recStack,A,a))
return true;
}
}
recStack[n] = false;
return false;
}
static void push(int v) {
if (marked[v]) {
t[v*2] = t[v*2+1] = t[v];
marked[v*2] = marked[v*2+1] = true;
marked[v] = false;
}
}
static void update1(int v, int tl, int tr, int l, int r, int new_val) {
if (l > r)
return;
if (l == tl && tr == r) {
t[v] = new_val;
marked[v] = true;
} else {
push(v);
int tm = (tl + tr) / 2;
update1(v*2, tl, tm, l, Math.min(r, tm), new_val);
update1(v*2+1, tm+1, tr, Math.max(l, tm+1), r, new_val);
}
}
static long get1(int v, int tl, int tr, int pos) {
if (tl == tr) {
return t[v];
}
push(v);
int tm = (tl + tr) / 2;
if (pos <= tm)
return get1(v*2, tl, tm, pos);
else
return get1(v*2+1, tm+1, tr, pos);
}
static int cost=0;
static void fmin(int i,int j,ArrayList<Integer> A,int cZ,int cO)
{
if(j-i>1)
{
int a=A.get(i),b=A.get(j);
cO+=Math.min(a, b);
if(a<b)
{
}
else if(b>a)
{
}
else
{
}
}
}
static void fs(int n,int p)
{
if(isWhite[n])countW[n]=1;
else countB[n]=1;
for(int c:g[n])
{
if(c!=p)
{
fs(c,n);
countB[n]+=countB[c];
countW[n]+=countW[c];
}
}
}
static int f(char X[],char Y[])
{
int s=0;
for(int i=0; i<Y.length; i++)
{
s+=Math.abs(X[i]-Y[i]);
}
return s;
}
public static long mergeSort(int A[],int l,int r)
{
long a=0;
if(l<r)
{
int m=(l+r)/2;
a+=mergeSort(A,l,m);
a+=mergeSort(A,m+1,r);
a+=merge(A,l,m,r);
}
return a;
}
public static long merge(int A[],int l,int m,int r)
{
long a=0;
int i=l,j=m+1,index=0;
long c=0;
int B[]=new int[r-l+1];
while(i<=m && j<=r)
{
if(A[i]<=A[j])
{
c++;
B[index++]=A[i++];
}
else
{
long s=(m-l)+1;
a+=(s-c);
B[index++]=A[j++];
}
}
while(i<=m)B[index++]=A[i++];
while(j<=r)B[index++]=A[j++];
index=0;
for(; l<=r; l++)A[l]=B[index++];
return a;
}
static int f(int A[])
{
int s=0;
for(int i=1; i<4; i++)
{
s+=Math.abs(A[i]-A[i-1]);
}
return s;
}
static boolean f(int A[],int B[],int N)
{
for(int i=0; i<N; i++)
{
if(Math.abs(A[i]-B[i])>1)return false;
}
return true;
}
static int [] prefix(char s[],int N) {
// int n = (int)s.length();
// vector<int> pi(n);
N=s.length;
int pi[]=new int[N];
for (int i = 1; i < N; i++) {
int j = pi[i-1];
while (j > 0 && s[i] != s[j])
j = pi[j-1];
if (s[i] == s[j])
j++;
pi[i] = j;
}
return pi;
}
static int count(long N)
{
int cnt=0;
long p=1L;
while(p<=N)
{
if((p&N)!=0)cnt++;
p<<=1;
}
return cnt;
}
static long kadane(long A[])
{
long lsum=A[0],gsum=0;
gsum=Math.max(gsum, lsum);
for(int i=1; i<A.length; i++)
{
lsum=Math.max(lsum+A[i],A[i]);
gsum=Math.max(gsum,lsum);
}
return gsum;
}
public static void reverse(int i,int j,int A[])
{
while(i<j)
{
int t=A[i];
A[i]=A[j];
A[j]=t;
i++;
j--;
}
}
public static int ask(int a,int b,int c)
{
System.out.println("? "+a+" "+b+" "+c);
return i();
}
static int[] reverse(int A[],int N)
{
int B[]=new int[N];
for(int i=N-1; i>=0; i--)
{
B[N-i-1]=A[i];
}
return B;
}
static boolean isPalin(char X[])
{
int i=0,j=X.length-1;
while(i<=j)
{
if(X[i]!=X[j])return false;
i++;
j--;
}
return true;
}
static int distance(int a,int b)
{
int d=D[a]+D[b];
int l=LCA(a,b);
l=2*D[l];
return d-l;
}
static int LCA(int a,int b)
{
if(D[a]<D[b])
{
int t=a;
a=b;
b=t;
}
int d=D[a]-D[b];
int p=1;
for(int i=0; i>=0 && p<=d; i++)
{
if((p&d)!=0)
{
a=lca[a][i];
}
p<<=1;
}
if(a==b)return a;
for(int i=max-1; i>=0; i--)
{
if(lca[a][i]!=-1 && lca[a][i]!=lca[b][i])
{
a=lca[a][i];
b=lca[b][i];
}
}
return lca[a][0];
}
static void dfs(int n,int p)
{
lca[n][0]=p;
if(p!=-1)D[n]=D[p]+1;
for(int c:g[n])
{
if(c!=p)
{
dfs(c,n);
}
}
}
static int[] prefix_function(char X[])//returns pi(i) array
{
int N=X.length;
int pre[]=new int[N];
for(int i=1; i<N; i++)
{
int j=pre[i-1];
while(j>0 && X[i]!=X[j])
j=pre[j-1];
if(X[i]==X[j])j++;
pre[i]=j;
}
return pre;
}
static int right(int A[],int Limit,int l,int r)
{
while(r-l>1)
{
int m=(l+r)/2;
if(A[m]<Limit)l=m;
else r=m;
}
return l;
}
static int left(int A[],int a,int l,int r)
{
while(r-l>1)
{
int m=(l+r)/2;
if(A[m]<a)l=m;
else r=m;
}
return l;
}
// static void build(int v,int tl,int tr,long A[])
// {
// if(tl==tr)
// {
// long a=0;
// if(A[tl]>0)
// {
// a=A[tl];
//
// }
// seg[v]=new node(a,a,a,A[tl],A[tl]);
// return;
// }
// int tm=(tl+tr)/2;
// build(v*2,tl,tm,A);
// build(v*2+1,tm+1,tr,A);
// seg[v]=combine(seg[v*2],seg[v*2+1]);
// }
// static node combine(node a,node b)
// {
// node temp=new node(0,0,0,0);
// temp.pref=max(a.pref,a.sum+b.pref,a.sum+b.sum);
// temp.suff=max(b.suff,b.sum+a.suff,b.sum+a.sum);
// temp.max=max(a.max,b.max,a.suff+b.pref);
// temp.sum=a.sum+b.sum;
// temp.min=Math.max(a.min, b.min);
// return temp;
// }
// static long max(long a,long b,long c)
// {
// return Math.max(a,Math.max(b, c));
// }
// // static void update(int v,int tl,int tr,int index)
// // {
// // if(index==tl && index==tr)
// // {
// // segR[v]+=1;
// // segR[v]%=2;
// // }
// // else
// // {
// // int tm=(tl+tr)/2;
// // if(index<=tm)update(v*2,tl,tm,index);
// // else update(v*2+1,tm+1,tr,index);
// // segR[v]=segR[v*2]+segR[v*2+1];
// // }
// // }
// static long ask(int v,int tl,int tr,int l,int r)
// {
//
// if(l>r)return 0;
// if(tl==l && r==tr)
// {
// return seg[v].max;
// }
// int tm=(tl+tr)/2;
//
// return Math.max(ask(v*2,tl,tm,l,Math.min(tm, r)),ask(v*2+1,tm+1,tr,Math.max(tm+1, l),r));
// }
static void build(int v,int tl,int tr,long A[])
{
if(tl==tr)
{
seg[v]=A[tl];
return;
}
int tm=(tl+tr)/2;
build(v*2,tl,tm,A);
build(v*2+1,tm+1,tr,A);
seg[v]=Math.max(seg[v*2],seg[v*2+1]);
}
static void update(int v,int tl,int tr,int index,int a)
{
if(index==tl && tl==tr)
{
seg[v]++;
seg[v]%=2;
}
else
{
int tm=(tl+tr)/2;
if(index<=tm)update(2*v,tl,tm,index,a);
else update(2*v+1,tm+1,tr,index,a);
seg[v]=seg[v*2]+seg[v*2+1];
}
}
static long ask(int v,int tl,int tr,int l,int r)
{
if(l>r)return 0;
if(tl==l && tr==r)return seg[v];
int tm=(tl+tr)/2;
return Math.max(ask(v*2,tl,tm,l,Math.min(tm,r)),ask(v*2+1,tm+1,tr,Math.max(l, tm+1),r));
}
static void updateC(int v,int tl,int tr,int index)
{
if(index==tl && index==tr)
{
segC[v]+=1;
segC[v]%=2;
}
else
{
int tm=(tl+tr)/2;
if(index<=tm)updateC(v*2,tl,tm,index);
else updateC(v*2+1,tm+1,tr,index);
segC[v]=segC[v*2]+segC[v*2+1];
}
}
static int askC(int v,int tl,int tr,int l,int r)
{
if(l>r)return 0;
if(tl==l && r==tr)
{
return segC[v];
}
int tm=(tl+tr)/2;
return askC(v*2,tl,tm,l,Math.min(tm, r))+askC(v*2+1,tm+1,tr,Math.max(tm+1, l),r);
}
static boolean f(long A[],long m,int N)
{
long B[]=new long[N];
for(int i=0; i<N; i++)
{
B[i]=A[i];
}
for(int i=N-1; i>=0; i--)
{
if(B[i]<m)return false;
if(i>=2)
{
long extra=Math.min(B[i]-m, A[i]);
long x=extra/3L;
B[i-2]+=2L*x;
B[i-1]+=x;
}
}
return true;
}
static int f(int l,int r,long A[],long x)
{
while(r-l>1)
{
int m=(l+r)/2;
if(A[m]>=x)l=m;
else r=m;
}
return r;
}
static boolean f(long m,long H,long A[],int N)
{
long s=m;
for(int i=0; i<N-1;i++)
{
s+=Math.min(m, A[i+1]-A[i]);
}
return s>=H;
}
static long ask(long l,long r)
{
System.out.println("? "+l+" "+r);
return l();
}
static long f(long N,long M)
{
long s=0;
if(N%3==0)
{
N/=3;
s=N*M;
}
else
{
long b=N%3;
N/=3;
N++;
s=N*M;
N--;
long a=N*M;
if(M%3==0)
{
M/=3;
a+=(b*M);
}
else
{
M/=3;
M++;
a+=(b*M);
}
s=Math.min(s, a);
}
return s;
}
static int ask(StringBuilder sb,int a)
{
System.out.println(sb+""+a);
return i();
}
static void swap(char X[],int i,int j)
{
char x=X[i];
X[i]=X[j];
X[j]=x;
}
static int min(int a,int b,int c)
{
return Math.min(Math.min(a, b), c);
}
static long and(int i,int j)
{
System.out.println("and "+i+" "+j);
return l();
}
static long or(int i,int j)
{
System.out.println("or "+i+" "+j);
return l();
}
static int len=0,number=0;
static void f(char X[],int i,int num,int l)
{
if(i==X.length)
{
if(num==0)return;
//update our num
if(isPrime(num))return;
if(l<len)
{
len=l;
number=num;
}
return;
}
int a=X[i]-'0';
f(X,i+1,num*10+a,l+1);
f(X,i+1,num,l);
}
static boolean is_Sorted(int A[])
{
int N=A.length;
for(int i=1; i<=N; i++)if(A[i-1]!=i)return false;
return true;
}
static boolean f(StringBuilder sb,String Y,String order)
{
StringBuilder res=new StringBuilder(sb.toString());
HashSet<Character> set=new HashSet<>();
for(char ch:order.toCharArray())
{
set.add(ch);
for(int i=0; i<sb.length(); i++)
{
char x=sb.charAt(i);
if(set.contains(x))continue;
res.append(x);
}
}
String str=res.toString();
return str.equals(Y);
}
static boolean all_Zero(int f[])
{
for(int a:f)if(a!=0)return false;
return true;
}
static long form(int a,int l)
{
long x=0;
while(l-->0)
{
x*=10;
x+=a;
}
return x;
}
static int count(String X)
{
HashSet<Integer> set=new HashSet<>();
for(char x:X.toCharArray())set.add(x-'0');
return set.size();
}
static int f(long K)
{
long l=0,r=K;
while(r-l>1)
{
long m=(l+r)/2;
if(m*m<K)l=m;
else r=m;
}
return (int)l;
}
static int [] sub(int A[],int B[])
{
int N=A.length;
int f[]=new int[N];
for(int i=N-1; i>=0; i--)
{
if(B[i]<A[i])
{
B[i]+=26;
B[i-1]-=1;
}
f[i]=B[i]-A[i];
}
for(int i=0; i<N; i++)
{
if(f[i]%2!=0)f[i+1]+=26;
f[i]/=2;
}
return f;
}
static int[] f(int N)
{
char X[]=in.next().toCharArray();
int A[]=new int[N];
for(int i=0; i<N; i++)A[i]=X[i]-'a';
return A;
}
static int max(int a ,int b,int c,int d)
{
a=Math.max(a, b);
c=Math.max(c,d);
return Math.max(a, c);
}
static int min(int a ,int b,int c,int d)
{
a=Math.min(a, b);
c=Math.min(c,d);
return Math.min(a, c);
}
static HashMap<Integer,Integer> Hash(int A[])
{
HashMap<Integer,Integer> mp=new HashMap<>();
for(int a:A)
{
int f=mp.getOrDefault(a,0)+1;
mp.put(a, f);
}
return mp;
}
static long mul(long a, long b)
{
return ( a %mod * 1L * b%mod )%mod;
}
static void swap(int A[],int a,int b)
{
int t=A[a];
A[a]=A[b];
A[b]=t;
}
static int find(int a)
{
if(par[a]<0)return a;
return par[a]=find(par[a]);
}
static void union(int a,int b)
{
a=find(a);
b=find(b);
if(a!=b)
{
if(par[a]>par[b]) //this means size of a is less than that of b
{
int t=b;
b=a;
a=t;
}
par[a]+=par[b];
par[b]=a;
}
}
static boolean isSorted(int A[])
{
for(int i=1; i<A.length; i++)
{
if(A[i]<A[i-1])return false;
}
return true;
}
static boolean isDivisible(StringBuilder X,int i,long num)
{
long r=0;
for(; i<X.length(); i++)
{
r=r*10+(X.charAt(i)-'0');
r=r%num;
}
return r==0;
}
static int lower_Bound(int A[],int low,int high, int x)
{
if (low > high)
if (x >= A[high])
return A[high];
int mid = (low + high) / 2;
if (A[mid] == x)
return A[mid];
if (mid > 0 && A[mid - 1] <= x && x < A[mid])
return A[mid - 1];
if (x < A[mid])
return lower_Bound( A, low, mid - 1, x);
return lower_Bound(A, mid + 1, high, x);
}
static String f(String A)
{
String X="";
for(int i=A.length()-1; i>=0; i--)
{
int c=A.charAt(i)-'0';
X+=(c+1)%2;
}
return X;
}
static void sortR(long[] a) //check for long
{
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
int N=a.length;
for (int i=0; i<a.length; i++) a[i]=l.get(N-i-1);
}
static void sort(long[] a) //check for long
{
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static String swap(String X,int i,int j)
{
char ch[]=X.toCharArray();
char a=ch[i];
ch[i]=ch[j];
ch[j]=a;
return new String(ch);
}
static int sD(long n)
{
if (n % 2 == 0 )
return 2;
for (int i = 3; i * i <= n; i += 2) {
if (n % i == 0 )
return i;
}
return (int)n;
}
// static void setGraph(int N,int nodes)
// {
//// size=new int[N+1];
// par=new int[N+1];
// col=new int[N+1];
//// g=new int[N+1][];
// D=new int[N+1];
// int deg[]=new int[N+1];
// int A[][]=new int[nodes][2];
// for(int i=0; i<nodes; i++)
// {
// int a=i(),b=i();
// A[i][0]=a;
// A[i][1]=b;
// deg[a]++;
// deg[b]++;
// }
// for(int i=0; i<=N; i++)
// {
// g[i]=new int[deg[i]];
// deg[i]=0;
// }
// for(int a[]:A)
// {
// int x=a[0],y=a[1];
// g[x][deg[x]++]=y;
// g[y][deg[y]++]=x;
// }
// }
static long pow(long a,long b)
{
//long mod=1000000007;
long pow=1;
long x=a;
while(b!=0)
{
if((b&1)!=0)pow=(pow*x)%mod;
x=(x*x)%mod;
b/=2;
}
return pow;
}
static long toggleBits(long x)//one's complement || Toggle bits
{
int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;
return ((1<<n)-1)^x;
}
static int countBits(long a)
{
return (int)(Math.log(a)/Math.log(2)+1);
}
static long fact(long N)
{
long n=2;
if(N<=1)return 1;
else
{
for(int i=3; i<=N; i++)n=(n*i)%mod;
}
return n;
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static boolean isPrime(long N)
{
if (N<=1) return false;
if (N<=3) return true;
if (N%2 == 0 || N%3 == 0) return false;
for (int i=5; i*i<=N; i=i+6)
if (N%i == 0 || N%(i+2) == 0)
return false;
return true;
}
static void print(char A[])
{
for(char c:A)System.out.print(c+" ");
System.out.println();
}
static void print(boolean A[])
{
for(boolean c:A)System.out.print(c+" ");
System.out.println();
}
static void print(int A[])
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static void print(long A[])
{
for(long i:A)System.out.print(i+ " ");
System.out.println();
}
static void print(boolean A[][])
{
for(boolean a[]:A)print(a);
}
static void print(long A[][])
{
for(long a[]:A)print(a);
}
static void print(int A[][])
{
for(int a[]:A)print(a);
}
static void print(ArrayList<Integer> A)
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static int i()
{
return in.nextInt();
}
static long l()
{
return in.nextLong();
}
static int[] input(int N){
int A[]=new int[N];
for(int i=0; i<N; i++)
{
A[i]=in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[]=new long[N];
for(int i=0; i<A.length; i++)A[i]=in.nextLong();
return A;
}
static long GCD(long a,long b)
{
if(b==0)
{
return a;
}
else return GCD(b,a%b );
}
}
class pair implements Comparable<pair>
{
int index,a;
pair(int index,int a)
{
this.index=index;
this.a=a;
// size=i;
}
public int compareTo(pair x)
{
return this.a-x.a;
}
}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while(st==null || !st.hasMoreElements())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
//
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | f5606b3a0cd720f5f71f7ec82a6fbc09 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution extends PrintWriter {
long MOD = 998_244_353L;
void solve() {
int n = sc.nextInt();
int k = sc.nextInt();
long[] dp = new long[n+1];
long[] dq = new long[n+1];
long[] ans = new long[n+1];
dq[0] = 1L;
int cur = 0;
for(int i = k; i <= n && cur <= n; i++) {
cur += i;
for(int j = cur; j <= n; j++) {
dp[j] = dp[j-i] + dq[j-i];
if(dp[j] >= MOD) dp[j] -= MOD;
ans[j] += dp[j];
if(ans[j] >= MOD) ans[j] -= MOD;
}
for(int j = cur; j <= n; j++) {
dq[j] = dp[j];
dp[j] = 0L;
}
}
for(int i = 1; i <= n; i++) print(ans[i] + " ");
println();
}
// Solution() throws FileNotFoundException { super(new File("saida_6.txt")); }
// InputReader sc = new InputReader(new FileInputStream("saida5.txt"));
Solution() { super(System.out); }
InputReader sc = new InputReader(System.in);
static class InputReader {
InputReader(InputStream in) { this.in = in; } InputStream in;
private byte[] buf = new byte[16384];
private int curChar;
private int numChars;
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = in.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1 || c == ';' ;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
public static void main(String[] $) {
new Thread(null, new Runnable() {
public void run() {
long start = System.nanoTime();
try {Solution solution = new Solution(); solution.solve(); solution.flush();}
catch (Exception e) {e.printStackTrace(); System.exit(1);}
System.err.println((System.nanoTime()-start)/1E9);
}
}, "1", 1 << 27).start();
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 766eb592a0bedbf3842bcde3813f2f99 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static ContestScanner sc = new ContestScanner(System.in);
static PrintWriter pw = new PrintWriter(System.out);
static StringBuilder sb = new StringBuilder();
static int mod = 998244353;
public static void main(String[] args) throws Exception {
//int T = sc.nextInt();
//for(int i = 0; i < T; i++)solve();
solve();
pw.flush();
}
public static void solve() {
int n = sc.nextInt();
int k = sc.nextInt();
int[] dp = new int[n+1];
int[] ans = new int[n+1];
dp[0] = 1;
for(int mn = 0; mn+k <= n; mn += k++){
int[] sum = new int[k];
for(int i = mn; i <= n; i++){
int cur = dp[i];
dp[i] = sum[i % k];
sum[i % k] = (sum[i % k]+cur) % mod;
ans[i] = (dp[i] + ans[i]) % mod;
}
}
for(int i = 1; i <= n; i++) sb.append(ans[i]).append(" ");
pw.println(sb.toString().trim());
sb.setLength(0);
}
static class GeekInteger {
public static void save_sort(int[] array) {
shuffle(array);
Arrays.sort(array);
}
public static int[] shuffle(int[] array) {
int n = array.length;
Random random = new Random();
for (int i = 0, j; i < n; i++) {
j = i + random.nextInt(n - i);
int randomElement = array[j];
array[j] = array[i];
array[i] = randomElement;
}
return array;
}
public static void save_sort(long[] array) {
shuffle(array);
Arrays.sort(array);
}
public static long[] shuffle(long[] array) {
int n = array.length;
Random random = new Random();
for (int i = 0, j; i < n; i++) {
j = i + random.nextInt(n - i);
long randomElement = array[j];
array[j] = array[i];
array[i] = randomElement;
}
return array;
}
}
}
/**
* refercence : https://github.com/NASU41/AtCoderLibraryForJava/blob/master/ContestIO/ContestScanner.java
*/
class ContestScanner {
private final java.io.InputStream in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private static final long LONG_MAX_TENTHS = 922337203685477580L;
private static final int LONG_MAX_LAST_DIGIT = 7;
private static final int LONG_MIN_LAST_DIGIT = 8;
public ContestScanner(java.io.InputStream in){
this.in = in;
}
public ContestScanner(java.io.File file) throws java.io.FileNotFoundException {
this(new java.io.BufferedInputStream(new java.io.FileInputStream(file)));
}
public ContestScanner(){
this(System.in);
}
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
}else{
ptr = 0;
try {
buflen = in.read(buffer);
} catch (java.io.IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() {
if (hasNextByte()) return buffer[ptr++]; else return -1;
}
private static boolean isPrintableChar(int c) {
return 33 <= c && c <= 126;
}
public boolean hasNext() {
while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
return hasNextByte();
}
public String next() {
if (!hasNext()) throw new java.util.NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext()) throw new java.util.NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while (true) {
if ('0' <= b && b <= '9') {
int digit = b - '0';
if (n >= LONG_MAX_TENTHS) {
if (n == LONG_MAX_TENTHS) {
if (minus) {
if (digit <= LONG_MIN_LAST_DIGIT) {
n = -n * 10 - digit;
b = readByte();
if (!isPrintableChar(b)) {
return n;
} else if (b < '0' || '9' < b) {
throw new NumberFormatException(
String.format("%d%s... is not number", n, Character.toString(b))
);
}
}
} else {
if (digit <= LONG_MAX_LAST_DIGIT) {
n = n * 10 + digit;
b = readByte();
if (!isPrintableChar(b)) {
return n;
} else if (b < '0' || '9' < b) {
throw new NumberFormatException(
String.format("%d%s... is not number", n, Character.toString(b))
);
}
}
}
}
throw new ArithmeticException(
String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit)
);
}
n = n * 10 + digit;
}else if(b == -1 || !isPrintableChar(b)){
return minus ? -n : n;
}else{
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() {
long nl = nextLong();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
return (int) nl;
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long[] nextLongArray(int length){
long[] array = new long[length];
for(int i=0; i<length; i++) array[i] = this.nextLong();
return array;
}
public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map){
long[] array = new long[length];
for(int i=0; i<length; i++) array[i] = map.applyAsLong(this.nextLong());
return array;
}
public int[] nextIntArray(int length){
int[] array = new int[length];
for(int i=0; i<length; i++) array[i] = this.nextInt();
return array;
}
public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map){
int[] array = new int[length];
for(int i=0; i<length; i++) array[i] = map.applyAsInt(this.nextInt());
return array;
}
public double[] nextDoubleArray(int length){
double[] array = new double[length];
for(int i=0; i<length; i++) array[i] = this.nextDouble();
return array;
}
public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map){
double[] array = new double[length];
for(int i=0; i<length; i++) array[i] = map.applyAsDouble(this.nextDouble());
return array;
}
public long[][] nextLongMatrix(int height, int width){
long[][] mat = new long[height][width];
for(int h=0; h<height; h++) for(int w=0; w<width; w++){
mat[h][w] = this.nextLong();
}
return mat;
}
public int[][] nextIntMatrix(int height, int width){
int[][] mat = new int[height][width];
for(int h=0; h<height; h++) for(int w=0; w<width; w++){
mat[h][w] = this.nextInt();
}
return mat;
}
public double[][] nextDoubleMatrix(int height, int width){
double[][] mat = new double[height][width];
for(int h=0; h<height; h++) for(int w=0; w<width; w++){
mat[h][w] = this.nextDouble();
}
return mat;
}
public char[][] nextCharMatrix(int height, int width){
char[][] mat = new char[height][width];
for(int h=0; h<height; h++){
String s = this.next();
for(int w=0; w<width; w++){
mat[h][w] = s.charAt(w);
}
}
return mat;
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 9915bf82c948777b5871918167998f62 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Main {
public static void main(String[]args) throws IOException {
new Main().run();
}
void run() throws IOException{
new solve().setIO(System.in, System.out).run();
}
class solve extends ioTask{
int t,n,s,k,i,j,len,h,m;
public void run() throws IOException {
n=in.in();
k=in.in();
int[][]dp=new int[2][n+1];
int[]sum=new int[n+1];
dp[0][0]=1;
int p=998244353;
int len;
for(int st=k,i=1,l=0;st<=n;st+=k,i^=1,l^=1) {
len=Math.min(st+k,n+1);
for(int j=st;j<len;j++) {
dp[i][j]=dp[l][j-k];
sum[j]+=dp[i][j];
sum[j]%=p;
}
for(int j=len;j<=n;j++) {
dp[i][j]=(dp[l][j-k]+dp[i][j-k])%p;
sum[j]+=dp[i][j];
sum[j]%=p;
}
k++;
}
for(int i=1;i<=n;i++)
out.print(sum[i]+" ");
out.println();
out.close();
}
}
class In{
private StringTokenizer in=new StringTokenizer("");
private InputStream is;
private BufferedReader bf;
public In(File file) throws IOException {
is=new FileInputStream(file);
init();
}
public In(InputStream is) throws IOException
{
this.is=is;
init();
}
private void init() throws IOException {
bf=new BufferedReader(new InputStreamReader(is));
}
boolean hasNext() throws IOException {
return in.hasMoreTokens()||bf.ready();
}
String ins() throws IOException {
while(!in.hasMoreTokens()) {
in=new StringTokenizer(bf.readLine());
}
return in.nextToken();
}
int in() throws IOException {
return Integer.parseInt(ins());
}
long inl() throws IOException {
return Long.parseLong(ins());
}
double ind() throws IOException {
return Double.parseDouble(ins());
}
}
class Out{
PrintWriter out;
private OutputStream os;
private void init() {
out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(os)));
}
public Out(File file) throws IOException {
os=new FileOutputStream(file);
init();
}
public Out(OutputStream os) throws IOException
{
this.os=os;
init();
}
}
class graph{
int[]to,nxt,head;
int cnt;
void init(int n) {
cnt=1;
for(int i=1;i<=n;i++)
{
head[i]=0;
}
}
public graph(int n,int m) {
to=new int[m+1];
nxt=new int[m+1];
head=new int[n+1];
cnt=1;
}
void add(int u,int v) {
to[cnt]=v;
nxt[cnt]=head[u];
head[u]=cnt++;
}
}
abstract class ioTask{
In in;
PrintWriter out;
public ioTask setIO(File in,File out) throws IOException{
this.in=new In(in);
this.out=new Out(out).out;
return this;
}
public ioTask setIO(File in,OutputStream out) throws IOException{
this.in=new In(in);
this.out=new Out(out).out;
return this;
}
public ioTask setIO(InputStream in,OutputStream out) throws IOException{
this.in=new In(in);
this.out=new Out(out).out;
return this;
}
public ioTask setIO(InputStream in,File out) throws IOException{
this.in=new In(in);
this.out=new Out(out).out;
return this;
}
void run()throws IOException{
}
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 2fa84ae20a7074aa2e01271aaf32bf0b | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class ChipMove {
private static final int MOD = 998244353;
public static void solve(FastIO io) {
final int N = io.nextInt();
final int K = io.nextInt();
int[] ans = new int[N + 1];
int[] ways = new int[N + 1];
int[] next = new int[N + 1];
ways[0] = 1;
int kMax = K;
int kSum = K;
while (kSum <= N) {
++kMax;
kSum += kMax;
}
for (int k = K; k <= kMax; ++k) {
Arrays.fill(next, 0);
for (int off = 0; off < k; ++off) {
int preSum = 0;
for (int i = off; i + k <= N; i += k) {
preSum = add(preSum, ways[i]);
next[i + k] = preSum;
}
}
for (int i = 1; i <= N; ++i) {
ans[i] = add(ans[i], next[i]);
}
int[] tmp = ways;
ways = next;
next = tmp;
}
io.printlnArray(Arrays.copyOfRange(ans, 1, N + 1));
}
private static int add(int a, int b) {
int val = a + b;
if (val >= MOD) {
val -= MOD;
}
return val;
}
public static class FastIO {
private InputStream reader;
private PrintWriter writer;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastIO(InputStream r, OutputStream w) {
reader = r;
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = reader.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
// TODO: read this byte-by-byte like the other read functions.
public double nextDouble() {
return Double.parseDouble(nextString());
}
public int[] nextIntArray(int n) {
return nextIntArray(n, 0);
}
public int[] nextIntArray(int n, int off) {
int[] arr = new int[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
return nextLongArray(n, 0);
}
public long[] nextLongArray(int n, int off) {
long[] arr = new long[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printArray(long[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printlnArray(int[] arr) {
printArray(arr);
writer.println();
}
public void printlnArray(long[] arr) {
printArray(arr);
writer.println();
}
public void printf(String format, Object... args) {
print(String.format(format, args));
}
public void flush() {
writer.flush();
}
}
public static void main(String[] args) {
FastIO io = new FastIO(System.in, System.out);
solve(io);
io.flush();
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 4b1b4c3706366deebcc73f760d0f8dd6 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class D {
static int MOD = 998244353;
static int MCNT = 633;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int[][] dp = new int[n+1][3];
for(int i = 0; i <= n; i += k)
dp[i][0] = dp[i][2] = 1;
boolean up = true;
int nk = k+1;
int sk = k;
while(MCNT --> 0) {
if(up) {
for(int i = sk; i < sk+nk; i++) {
int pref = 0;
for(int j = i; j <= n; j += nk) {
dp[j][2] += dp[j][1] = pref;
dp[j][2] %= MOD;
pref = (pref + dp[j][0]) % MOD;
}
}
}else {
for(int i = sk; i < sk+nk; i++) {
int pref = 0;
for(int j = i; j <= n; j += nk) {
dp[j][2] += dp[j][0] = pref;
dp[j][2] %= MOD;
pref = (pref + dp[j][1]) % MOD;
}
}
}
up = !up;
sk += nk;
nk++;
}
for(int i = 1; i < dp.length; i++)
pw.print(dp[i][2] + " ");
pw.close();
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 21ef8e06c10644c0f2c940254e871c57 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static Scanner sc;
static PrintWriter out;
public static void main(String[] args) {
sc = new Scanner(System.in);
out = new PrintWriter(System.out);
int t = 1;
if (false) {
t = sc.nextInt();
}
for(int i=0; i<t; i++) {
new Main().solve();
}
out.flush();
}
public void solve() {
int n = sc.nextInt();
int k = sc.nextInt();
int[] res = new int[n+1];
int[] prev = new int[n+1];
prev[0] = 1;
int first = 0;
int t = 0;
int mod = 998244353;
while(true) {
int d = k + t;
first += d;
if(first > n) break;
int[] next = new int[n+1];
for(int i = first; i<=n; i++) {
next[i] = prev[i-d];
prev[i] += next[i];
prev[i] %= mod;
res[i] += next[i];
res[i] %= mod;
}
prev = next;
t++;
}
for(int i=1; i<=n; i++) {
if(i>1) out.print(" ");
out.print(res[i]);
}
out.println();
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | e33590df7912e5f89a9c4d5fbd503072 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.StringTokenizer;
public class AMain {
private QuickReader in;
private PrintWriter out;
public AMain(QuickReader in, PrintWriter out) {
this.in = in;
this.out = out;
}
public static void main(String[] args) throws IOException {
QuickReader in = new QuickReader(System.in);
try(PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));)
{
new AMain(in, out).solve();
}
}
public final int MOD = 998244353;
private void solve() throws IOException {
int n = in.nextInt();
int k = in.nextInt();
int[] res = new int[n+1];
int[][] dp = new int[2][n+1];
dp[0][0] = 1;
for(int i=k;;i++)
{
boolean anyPresent=false;
for(int j=0;j<=n;j++)
{
res[j] = (res[j] + dp[0][j])%MOD;
if(dp[0][j]!=0)
anyPresent=true;
}
if(!anyPresent)
break;
for(int j=0;j<=n;j++)
dp[1][j] = (j-i >= 0)? (dp[0][j-i] + dp[1][j-i])%MOD : 0;
int[] tmp = dp[1];
dp[1] = dp[0];
dp[0] = tmp;
}
print(Arrays.copyOfRange(res, 1, n+1));
}
void print(int[] a)
{
for(int i=0;i<a.length;i++)
{
if(i>0)
out.print(' ');
out.print(a[i]);
}
out.println();
}
}
class QuickReader
{
BufferedReader in;
StringTokenizer token;
public QuickReader(InputStream ins)
{
in=new BufferedReader(new InputStreamReader(ins));
token=new StringTokenizer("");
}
public boolean hasNext()
{
while (!token.hasMoreTokens())
{
try
{
String s = in.readLine();
if (s == null) return false;
token = new StringTokenizer(s);
} catch (IOException e)
{
throw new InputMismatchException();
}
}
return true;
}
public String next()
{
hasNext();
return token.nextToken();
}
public double nextDouble()
{
return Double.parseDouble(next());
}
public int nextInt()
{
return Integer.parseInt(next());
}
public int[] nextInts(int n)
{
int[] res = new int[n];
for (int i = 0; i < n; i++)
res[i] = nextInt();
return res;
}
public long nextLong() {
return Long.parseLong(next());
}
public long[] nextLongs(int n)
{
long[] res = new long[n];
for (int i = 0; i < n; i++)
res[i] = nextLong();
return res;
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 3f22d386f789f42823c69d4ace51b1b2 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
//BufferedReader f = new BufferedReader(new FileReader("uva.in"));
//PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("threesum.out")));
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
StringTokenizer st = new StringTokenizer(f.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int[] ans = new int[n+1];
int[][] dp = new int[2][n+1];
ans[0] = dp[0][0] = 1;
int idx = 1;
for(int i = 1; i < 632; i++) {
for(int j = 0; j <= Math.min(n, k+i-2); j++) {
dp[idx][j] = 0;
}
for(int j = k+i-1; j <= n; j++) {
dp[idx][j] = (dp[idx][j-(k+i-1)]+dp[idx^1][j-(k+i-1)])%998244353;
ans[j] = (ans[j]+dp[idx][j])%998244353;
}
idx ^= 1;
}
out.print(ans[1]);
for(int i = 2; i <= n; i++) {
out.print(" " + ans[i]);
}
out.println();
f.close();
out.close();
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 5914f0382bf6c7e39982a86b71027a76 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class D {
static final int INF = 998244353;
public static void main(String[] args) throws IOException {
StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int[] ans = new int[n+1];
int[] dp = new int[n+1-k];
int start = k;
for (int i = 0; i <= n-start; i += k) {
dp[i] = 1; // i번째 자리: i+start의 가짓수
ans[i+start] += 1;
}
start += k+1;
for (int t = 1; t < 650; t++) {
if (start > n) break;
int[] temp = new int[n+1-start];
for (int i = 0; i <= n-start; i++) {
temp[i] += dp[i];
temp[i] %= INF;
if (i >= k+t) temp[i] += temp[i-k-t];
temp[i] %= INF;
ans[i+start] += temp[i];
ans[i+start] %= INF;
}
start += (k+t+1);
dp = temp;
}
for (int i = 1; i <= n; i++) {
sb.append(ans[i]+" ");
}
System.out.println(sb.toString());
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | b5bf5ae6ba09d6f9c5e3baa8f69395a6 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class testing {
public static void main(String[] args) throws IOException {
FastScanner input = new FastScanner(false);
int t = 1;//input.nextInt();
PrintWriter out = new PrintWriter(System.out);
for (int iter = 0; iter<t; iter++) {
int N = input.nextInt();
int K = input.nextInt();
int[] dp = new int[N];
dp[0]=1;
int[] res = new int[N+1];
for (int k = K; k<=N; k++) {
int[] n = new int[N+1];
for (int i = k; i<=N; i++) {
n[i]=(n[i-k]+dp[i-k])%998244353;
}
for (int i = 0; i<=N; i++) res[i]=(res[i]+n[i])%998244353;
dp=n;
boolean works = false;
for (int i = 0; i<=N; i++) {
if (n[i]!=0) {
works=true;
break;
}
}
if (!works) break;
}
for (int i = 1; i<=N; i++) {
out.print(res[i]+" ");
}
out.println();
}
out.close();
}
private static class FastScanner {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
private FastScanner(boolean usingFile) throws IOException {
if (usingFile) din=new DataInputStream(new FileInputStream("C:\\Users\\skwek\\IdeaProjects\\HelloWorld\\src\\testing.in"));
else din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
private short nextShort() throws IOException {
short ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do ret = (short)(ret * 10 + c - '0');
while ((c = read()) >= '0' && c <= '9');
if (neg) return (short)-ret;
return ret;
}
private int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do ret = ret * 10 + c - '0';
while ((c = read()) >= '0' && c <= '9');
if (neg) return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do ret = ret * 10 + c - '0';
while ((c = read()) >= '0' && c <= '9');
if (neg) return -ret;
return ret;
}
private char nextChar() throws IOException {
byte c = read();
while (c <= ' ') c = read();
return (char)c;
}
private String nextString() throws IOException {
StringBuilder ret = new StringBuilder();
byte c = read();
while (c <=' ') c = read();
do {
ret.append((char)c);
} while ((c = read())>' ');
return ret.toString();
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | a713c10f8626e5e03ad5d2491289d7a0 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
*
* @author SAMUEL
*/
public class Main {
public static void main(String[] args) {
FastReader sc=new FastReader();
int n1=sc.nextInt();
int k=sc.nextInt();
int mod=998244353;
int[] dp=new int[n1+1];
int[] total=new int[n1+1];
dp[0]=1;
for(int pas=0;pas+k<=n1;pas+=k++){
int[] dp2=new int[k];
for(int num=pas;num<=n1;num++){
int vc=dp[num];
dp[num]=dp2[num%k];
dp2[num%k]=(dp2[num%k]+vc)%mod;
total[num]=(total[num]+dp[num] )%mod;
}
}
StringBuilder sal=new StringBuilder();
for(int i=1;i<=n1;i++){
sal.append(total[i]+" ");
}
System.out.println(sal.toString());
}
static int upper_bound(long arr[], long key)
{
int mid, N = arr.length;
int low = 0;
int high = N;
// Till low is less than high
while (low < high && low != N) {
// Find the index of the middle element
mid = low + (high - low) / 2;
if (key >= arr[mid]) {
low = mid + 1;
}
else {
high = mid;
}
}
if (low == N ) {
return N;
}
return low;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 8fe8b109420145a4191ffa1fd56799df | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class CF1{
public static void main(String[] args) {
FastScanner sc=new FastScanner();
// hamare saath shree raghunath to kis baat ki chinta...
// int T=sc.nextInt();
int T=1;
for (int tt=1; tt<=T; tt++){
int n =sc.nextInt();
int k =sc.nextInt();
int lim=0;
int sum=0;
int temp=k;
while (sum<n){
lim++;
sum+=temp;
temp++;
}
int prev[]=new int [n+1];
int ans []= new int [n+1];
int curr[]= new int [n+1];
prev[0]=1;
for (int i=0; i<lim; i++){
for (int j=1; j<=n; j++){
if (j>=k){
prev[j]=(prev[j]+prev[j-k])%mod2;
}
}
for (int j=1; j<=n;j++){
if (j>=k) curr[j]=prev[j-k];
ans[j]+=curr[j];
ans[j]%=mod2;
}
prev=curr;
curr= new int [n+1];
k++;
}
StringBuilder sb= new StringBuilder();
for (int i=1; i<=n; i++ ) sb.append(ans[i]+" ");
System.out.println(sb);
}
}
static long prime(long n){
for (long i=3; i*i<=n; i+=2){
if (n%i==0) return i;
}
return -1;
}
static long factorial (int x){
if (x==0) return 1;
long ans =x;
for (int i=x-1; i>=1; i--){
ans*=i;
ans%=mod;
}
return ans;
}
static boolean killMePls = false;
// public static void main(String[] args) throws Exception {
// Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() {
// public void uncaughtException(Thread t, Throwable e) {killMePls = true;}
// };
// Thread t = new Thread(null, ()->A(args), "", 1<<28);
// t.setUncaughtExceptionHandler(h);
// t.start();
// t.join();
// if(killMePls) throw null;
// }
static int mod2= 998244353;
static long mod=1000000007L;
static long power2 (long a, long b){
long res=1;
while (b>0){
if ((b&1)== 1){
res= (res * a % mod)%mod;
}
a=(a%mod * a%mod)%mod;
b=b>>1;
}
return res;
}
static void sort(int[] a){
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void sortLong(long[] a){
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static long gcd (long n, long m){
if (m==0) return n;
else return gcd(m, n%m);
}
static class Pair implements Comparable<Pair>{
int x,y;
private static final int hashMultiplier = BigInteger.valueOf(new Random().nextInt(1000) + 100).nextProbablePrime().intValue();
public Pair(int x, int y){
this.x = x;
this.y = y;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pii = (Pair) o;
if (x != pii.x) return false;
return y == pii.y;
}
public int hashCode() {
return hashMultiplier * x + y;
}
public int compareTo(Pair o){
// if (this.x==o.x) return Integer.compare(this.y,o.y);
// else return Integer.compare(this.x,o.x);
return Integer.compare(this.y,o.y);
}
// this.x-o.x is ascending
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 1bf6302ca7f5620c8503c58651b676e9 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
public class UWI {
//#0.00代表保留两位小数
static DecimalFormat df = new DecimalFormat("#0.00000000");
void solve() {
for (int T = 1; T > 0; T--) go();
}
void go() {
int MOD = 998244353;
int n = ni(), k = ni();
int[] dp = new int[n + 1];//走到位置i 用了s步
int[] ans = new int[n + 1];
dp[0] = 1;
//mn是 前i步最少走的总距离 k=k+s
for (int mn = 0; mn + k <= n; mn += k++) {//for s 保证s+1合法
int[] sum = new int[k];
for (int i = mn; i <= n; ++i) { //当前位置i
int cur = dp[i];//dp[i][s]
dp[i] = sum[i % k];// dp[i][s+1]=sum[i%k][s]
sum[i % k] = (sum[i % k] + cur) % MOD;
ans[i] = (ans[i] + dp[i]) % MOD;
}
}
for (int i = 1; i <= n; i++) {
out.print(ans[i] + " ");
}
out.println();
}
public static void main(String[] args) throws Exception {
new UWI().run();
}
void run() throws Exception {
if (INPUT.length() > 0)
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
else is = oj ? System.in : new ByteArrayInputStream(new FileInputStream("input/a.test").readAllBytes());
out = new FastWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis() - s + "ms");
}
InputStream is;
FastWriter out;
String INPUT = "";
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
private double nd() {
return Double.parseDouble(ns());
}
private char nc() {
return (char) skip();
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private String nextLine() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b) && b != ' ')) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = ni();
return a;
}
private long[] nal(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nl();
return a;
}
//二维数组
private char[][] nm(int n, int m) {
char[][] map = new char[n][];
for (int i = 0; i < n; i++) map[i] = ns(m);
return map;
}
private int[][] nmi(int n, int m) {
int[][] map = new int[n][];
for (int i = 0; i < n; i++) map[i] = na(m);
return map;
}
//int
private int ni() {
return (int) nl();
}
//long
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
public static class FastWriter {
private static final int BUF_SIZE = 1 << 13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter() {
out = null;
}
public FastWriter(OutputStream os) {
this.out = os;
}
public FastWriter(String path) {
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b) {
buf[ptr++] = b;
if (ptr == BUF_SIZE) innerflush();
return this;
}
public FastWriter write(char c) {
return write((byte) c);
}
public FastWriter write(char[] s) {
for (char c : s) {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE) innerflush();
}
return this;
}
public FastWriter write(String s) {
s.chars().forEach(c -> {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE) innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000) return 10;
if (l >= 100000000) return 9;
if (l >= 10000000) return 8;
if (l >= 1000000) return 7;
if (l >= 100000) return 6;
if (l >= 10000) return 5;
if (l >= 1000) return 4;
if (l >= 100) return 3;
if (l >= 10) return 2;
return 1;
}
public FastWriter write(int x) {
if (x == Integer.MIN_VALUE) {
return write((long) x);
}
if (ptr + 12 >= BUF_SIZE) innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L) return 19;
if (l >= 100000000000000000L) return 18;
if (l >= 10000000000000000L) return 17;
if (l >= 1000000000000000L) return 16;
if (l >= 100000000000000L) return 15;
if (l >= 10000000000000L) return 14;
if (l >= 1000000000000L) return 13;
if (l >= 100000000000L) return 12;
if (l >= 10000000000L) return 11;
if (l >= 1000000000L) return 10;
if (l >= 100000000L) return 9;
if (l >= 10000000L) return 8;
if (l >= 1000000L) return 7;
if (l >= 100000L) return 6;
if (l >= 10000L) return 5;
if (l >= 1000L) return 4;
if (l >= 100L) return 3;
if (l >= 10L) return 2;
return 1;
}
public FastWriter write(long x) {
if (x == Long.MIN_VALUE) {
return write("" + x);
}
if (ptr + 21 >= BUF_SIZE) innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision) {
if (x < 0) {
write('-');
x = -x;
}
x += Math.pow(10, -precision) / 2;
// if(x < 0){ x = 0; }
write((long) x).write(".");
x -= (long) x;
for (int i = 0; i < precision; i++) {
x *= 10;
write((char) ('0' + (int) x));
x -= (int) x;
}
return this;
}
public FastWriter writeln(char c) {
return write(c).writeln();
}
public FastWriter writeln(int x) {
return write(x).writeln();
}
public FastWriter writeln(long x) {
return write(x).writeln();
}
public FastWriter writeln(double x, int precision) {
return write(x, precision).writeln();
}
public FastWriter write(int... xs) {
boolean first = true;
for (int x : xs) {
if (!first) write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs) {
boolean first = true;
for (long x : xs) {
if (!first) write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln() {
return write((byte) '\n');
}
public FastWriter writeln(int... xs) {
return write(xs).writeln();
}
public FastWriter writeln(long... xs) {
return write(xs).writeln();
}
public FastWriter writeln(char[] line) {
return write(line).writeln();
}
public FastWriter writeln(char[]... map) {
for (char[] line : map) write(line).writeln();
return this;
}
public FastWriter writeln(String s) {
return write(s).writeln();
}
private void innerflush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush() {
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) {
return write(b);
}
public FastWriter print(char c) {
return write(c);
}
public FastWriter print(char[] s) {
return write(s);
}
public FastWriter print(String s) {
return write(s);
}
public FastWriter print(int x) {
return write(x);
}
public FastWriter print(long x) {
return write(x);
}
public FastWriter print(double x, int precision) {
return write(x, precision);
}
public FastWriter println(char c) {
return writeln(c);
}
public FastWriter println(int x) {
return writeln(x);
}
public FastWriter println(long x) {
return writeln(x);
}
public FastWriter println(double x, int precision) {
return writeln(x, precision);
}
public FastWriter print(int... xs) {
return write(xs);
}
public FastWriter print(long... xs) {
return write(xs);
}
public FastWriter println(int... xs) {
return writeln(xs);
}
public FastWriter println(long... xs) {
return writeln(xs);
}
public FastWriter println(char[] line) {
return writeln(line);
}
public FastWriter println(char[]... map) {
return writeln(map);
}
public FastWriter println(String s) {
return writeln(s);
}
public FastWriter println() {
return writeln();
}
}
//打印非零?
public void trnz(int... o) {
for (int i = 0; i < o.length; i++) if (o[i] != 0) System.out.print(i + ":" + o[i] + " ");
System.out.println();
}
// print ids which are 1
public void trt(long... o) {
Queue<Integer> stands = new ArrayDeque<>();
for (int i = 0; i < o.length; i++) {
for (long x = o[i]; x != 0; x &= x - 1) stands.add(i << 6 | Long.numberOfTrailingZeros(x));
}
System.out.println(stands);
}
public void tf(boolean... r) {
for (boolean x : r) System.out.print(x ? '#' : '.');
System.out.println();
}
public void tf(boolean[]... b) {
for (boolean[] r : b) {
for (boolean x : r) System.out.print(x ? '#' : '.');
System.out.println();
}
System.out.println();
}
public void tf(long[]... b) {
if (INPUT.length() != 0) {
for (long[] r : b) {
for (long x : r) {
for (int i = 0; i < 64; i++) {
System.out.print(x << ~i < 0 ? '#' : '.');
}
}
System.out.println();
}
System.out.println();
}
}
public void tf(long... b) {
if (INPUT.length() != 0) {
for (long x : b) {
for (int i = 0; i < 64; i++) {
System.out.print(x << ~i < 0 ? '#' : '.');
}
}
System.out.println();
}
}
private final boolean oj = !local();
boolean local() {
try {
String user = System.getProperty("user.name");
return user.contains("dpz");
} catch (Exception ignored) {
}
return false;
}
//调试的时候打印
private void tr(Object... o) {
if (!oj) System.out.println(Arrays.deepToString(o));
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 1dff844c5db0553ea2a6c94256c90fbd | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.util.*;
import java.io.*;
public class D {
static class Scan {
private byte[] buf=new byte[1024];
private int index;
private InputStream in;
private int total;
public Scan()
{
in=System.in;
}
public int scan()throws IOException
{
if(total<0)
throw new InputMismatchException();
if(index>=total)
{
index=0;
total=in.read(buf);
if(total<=0)
return -1;
}
return buf[index++];
}
public int scanInt()throws IOException
{
int integer=0;
int n=scan();
while(isWhiteSpace(n))
n=scan();
int neg=1;
if(n=='-')
{
neg=-1;
n=scan();
}
while(!isWhiteSpace(n))
{
if(n>='0'&&n<='9')
{
integer*=10;
integer+=n-'0';
n=scan();
}
else throw new InputMismatchException();
}
return neg*integer;
}
public double scanDouble()throws IOException
{
double doub=0;
int n=scan();
while(isWhiteSpace(n))
n=scan();
int neg=1;
if(n=='-')
{
neg=-1;
n=scan();
}
while(!isWhiteSpace(n)&&n!='.')
{
if(n>='0'&&n<='9')
{
doub*=10;
doub+=n-'0';
n=scan();
}
else throw new InputMismatchException();
}
if(n=='.')
{
n=scan();
double temp=1;
while(!isWhiteSpace(n))
{
if(n>='0'&&n<='9')
{
temp/=10;
doub+=(n-'0')*temp;
n=scan();
}
else throw new InputMismatchException();
}
}
return doub*neg;
}
public String scanString()throws IOException
{
StringBuilder sb=new StringBuilder();
int n=scan();
while(isWhiteSpace(n))
n=scan();
while(!isWhiteSpace(n))
{
sb.append((char)n);
n=scan();
}
return sb.toString();
}
private boolean isWhiteSpace(int n)
{
if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
return true;
return false;
}
}
public static void sort(int arr[],int l,int r) { //sort(arr,0,n-1);
if(l==r) {
return;
}
int mid=(l+r)/2;
sort(arr,l,mid);
sort(arr,mid+1,r);
merge(arr,l,mid,mid+1,r);
}
public static void merge(int arr[],int l1,int r1,int l2,int r2) {
int tmp[]=new int[r2-l1+1];
int indx1=l1,indx2=l2;
//sorting the two halves using a tmp array
for(int i=0;i<tmp.length;i++) {
if(indx1>r1) {
tmp[i]=arr[indx2];
indx2++;
continue;
}
if(indx2>r2) {
tmp[i]=arr[indx1];
indx1++;
continue;
}
if(arr[indx1]<arr[indx2]) {
tmp[i]=arr[indx1];
indx1++;
continue;
}
tmp[i]=arr[indx2];
indx2++;
}
//Copying the elements of tmp into the main array
for(int i=0,j=l1;i<tmp.length;i++,j++) {
arr[j]=tmp[i];
}
}
public static void sort(long arr[],int l,int r) { //sort(arr,0,n-1);
if(l==r) {
return;
}
int mid=(l+r)/2;
sort(arr,l,mid);
sort(arr,mid+1,r);
merge(arr,l,mid,mid+1,r);
}
public static void merge(long arr[],int l1,int r1,int l2,int r2) {
long tmp[]=new long[r2-l1+1];
int indx1=l1,indx2=l2;
//sorting the two halves using a tmp array
for(int i=0;i<tmp.length;i++) {
if(indx1>r1) {
tmp[i]=arr[indx2];
indx2++;
continue;
}
if(indx2>r2) {
tmp[i]=arr[indx1];
indx1++;
continue;
}
if(arr[indx1]<arr[indx2]) {
tmp[i]=arr[indx1];
indx1++;
continue;
}
tmp[i]=arr[indx2];
indx2++;
}
//Copying the elements of tmp into the main array
for(int i=0,j=l1;i<tmp.length;i++,j++) {
arr[j]=tmp[i];
}
}
static int k,mod;
public static void main(String args[]) throws IOException {
Scan input=new Scan();
StringBuilder ans=new StringBuilder("");
int test=1;
for(int tt=1;tt<=test;tt++) {
int n=input.scanInt();
k=input.scanInt();
mod=998244353;
int arr[]=solve1(n);
for(int i=1;i<arr.length;i++) {
ans.append(arr[i]+" ");
}
ans.append("\n");
}
System.out.print(ans);
}
public static int[] solve1(int n) {
int sum[]=new int[n+1];
int arr[][]=new int[2][n+1];
int prefix[][]=new int[2][n+1];
int curr=0,prev=-1;
for(int i=0;i<650;i++) {
for(int j=1;j<arr[0].length;j++) {
if(i==0) {
if(j%k==0) {
arr[curr][j]=1;
}
prefix[curr][j]=arr[curr][j]+((j-(k+i+1)>=0)?prefix[curr][j-((k+i+1))]:0);
prefix[curr][j]%=mod;
sum[j]+=arr[curr][j];
sum[j]%=mod;
continue;
}
arr[curr][j]=(j-(k+i)>=0)?prefix[prev][j-(k+i)]:0;
prefix[curr][j]=arr[curr][j]+((j-(k+i+1)>=0)?prefix[curr][j-((k+i+1))]:0);
prefix[curr][j]%=mod;
sum[j]+=arr[curr][j];
sum[j]%=mod;
}
curr++;
prev++;
curr%=2;
prev%=2;
}
return sum;
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 752bb35dd3bc4bb9565c06403dec0e46 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | /*
"Everything in the universe is balanced. Every disappointment
you face in life will be balanced by something good for you!
Keep going, never give up."
Just have Patience + 1...
*/
import java.util.*;
import java.lang.*;
import java.io.*;
public class Solution {
static int INF = (int) 1e9 + 7, MOD = 998244353;
public static void main(String[] args) throws java.lang.Exception {
out = new PrintWriter(new BufferedOutputStream(System.out));
sc = new FastReader();
int test = 1;
for (int t = 1; t <= test; t++) {
solve(t);
}
out.close();
}
private static void solve(int t) {
int n = sc.nextInt();
int k = sc.nextInt();
int[] noOfWays = new int[n + 1];
int[] dp = new int[n + 1];
dp[0] = 1;
int moves = 0;
while (moves < n) {
int[] next = new int[n + 1];
for (int i = k; i <= n; i++) {
next[i] = next[i - k] + dp[i - k];
next[i] %= MOD;
noOfWays[i] += next[i];
noOfWays[i] %= MOD;
}
dp = next;
moves += k;
k++;
}
for (int i = 1; i <= n; i++) {
out.print(noOfWays[i] + " ");
}
out.println();
}
public static FastReader sc;
public static PrintWriter out;
static class FastReader
{
BufferedReader br;
StringTokenizer str;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (str == null || !str.hasMoreElements())
{
try
{
str = new StringTokenizer(br.readLine());
}
catch (IOException lastMonthOfVacation)
{
lastMonthOfVacation.printStackTrace();
}
}
return str.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException lastMonthOfVacation)
{
lastMonthOfVacation.printStackTrace();
}
return str;
}
}
}
| Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | 863276c27fb0fe0a088096d3fd376563 | train_109.jsonl | 1659623700 | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the length of the second move — by $$$k+1$$$, the third — by $$$k+2$$$, and so on.For example, if $$$k=2$$$, then the sequence of moves may look like this: $$$0 \rightarrow 4 \rightarrow 7 \rightarrow 19 \rightarrow 44$$$, because $$$4 - 0 = 4$$$ is divisible by $$$2 = k$$$, $$$7 - 4 = 3$$$ is divisible by $$$3 = k + 1$$$, $$$19 - 7 = 12$$$ is divisible by $$$4 = k + 2$$$, $$$44 - 19 = 25$$$ is divisible by $$$5 = k + 3$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to count the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if they differ as sets of visited positions. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static int mod = 998244353;
//static int mod = (int)1e9+7;
static boolean[] prime = new boolean[1];
static int[][] dir1 = new int[][]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
static int[][] dir2 = new int[][]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
static int inf = 0x3f3f3f3f;
static {
for (int i = 2; i < prime.length; i++)
prime[i] = true;
for (int i = 2; i < prime.length; i++) {
if (prime[i]) {
for (int k = 2; i * k < prime.length; k++) {
prime[i * k] = false;
}
}
}
}
static class DSU {
int[] fa;
DSU(int n) {
fa = new int[n];
for (int i = 0; i < n; i++)
fa[i] = i;
}
int find(int t) {
if (t != fa[t])
fa[t] = find(fa[t]);
return fa[t];
}
void join(int x, int y) {
x = find(x);
y = find(y);
fa[x] = y;
}
}
static List<Integer>[] lists;
static void init(int n) {
lists = new List[n];
for(int i = 0; i< n;i++){
lists[i] = new ArrayList<>();
}
}
static class LCA{
int[] dep;
int[][] fa;
int[] log;
boolean[] v;
public LCA(int n){
dep = new int[n+5];
log = new int[n+5];
fa = new int[n+5][31];
v = new boolean[n+5];
for (int i = 2; i <= n; ++i) {
log[i] = log[i/2] + 1;
}
dfs(1,0);
}
private void dfs(int cur, int pre){
if(v[cur]) return;
v[cur] = true;
dep[cur] = dep[pre]+1;
fa[cur][0] = pre;
for (int i = 1; i <= log[dep[cur]]; ++i) {
fa[cur][i] = fa[fa[cur][i - 1]][i - 1];
}
for(int i : lists[cur]){
dfs(i,cur);
}
}
private int lca(int a, int b){
if(dep[a] > dep[b]){
int t = a;
a = b;
b = t;
}
while (dep[a] != dep[b]){
b = fa[b][log[dep[b] - dep[a]]];
}
if(a == b) return a;
for (int k = log[dep[a]]; k >= 0; k--) {
if (fa[a][k] != fa[b][k]) {
a = fa[a][k]; b = fa[b][k];
}
}
return fa[a][0];
}
}
static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
static long lcm(long a, long b) {
return a * b / gcd(a, b);
}
static int get() throws Exception {
String ss = bf.readLine();
if (ss.contains(" "))
ss = ss.substring(0, ss.indexOf(" "));
return Integer.parseInt(ss);
}
static long getx() throws Exception {
String ss = bf.readLine();
if (ss.contains(" "))
ss = ss.substring(0, ss.indexOf(" "));
return Long.parseLong(ss);
}
static int[] getint() throws Exception {
String[] s = bf.readLine().split(" ");
int[] a = new int[s.length];
for (int i = 0; i < a.length; i++) {
a[i] = Integer.parseInt(s[i]);
}
return a;
}
static long[] getlong() throws Exception {
String[] s = bf.readLine().split(" ");
long[] a = new long[s.length];
for (int i = 0; i < a.length; i++) {
a[i] = Long.parseLong(s[i]);
}
return a;
}
static String getstr() throws Exception {
return bf.readLine();
}
static void println() throws Exception {
bw.write("\n");
}
static void print(int a) throws Exception {
bw.write(a + "\n");
}
static void print(long a) throws Exception {
bw.write(a + "\n");
}
static void print(String a) throws Exception {
bw.write(a + "\n");
}
static void print(int[] a) throws Exception {
for (int i : a) {
bw.write(i + " ");
}
println();
}
static void print(long[] a) throws Exception {
for (long i : a) {
bw.write(i + " ");
}
println();
}
static void print(int[][] a) throws Exception {
for (int i[] : a)
print(i);
}
static void print(long[][] a) throws Exception {
for (long[] i : a)
print(i);
}
static void print(char[] a) throws Exception {
for (char i : a) {
bw.write(i + "");
}
println();
}
static long pow(long a, long b) {
long ans = 1;
while (b > 0) {
if ((b & 1) == 1) {
ans *= a;
}
a *= a;
b >>= 1;
}
return ans;
}
static int powmod(long a, long b, int mod) {
long ans = 1;
while (b > 0) {
if ((b & 1) == 1) {
ans = ans * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return (int) ans;
}
static void sort(int[] a) {
int n = a.length;
Integer[] b = new Integer[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[i];
}
static void sort(long[] a) {
int n = a.length;
Long[] b = new Long[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[i];
}
static void resort(int[] a) {
int n = a.length;
Integer[] b = new Integer[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[n - 1 - i];
}
static void resort(long[] a) {
int n = a.length;
Long[] b = new Long[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[n - 1 - i];
}
static int max(int a, int b) {
return Math.max(a, b);
}
static int min(int a, int b) {
return Math.min(a, b);
}
static long max(long a, long b) {
return Math.max(a, b);
}
static long min(long a, long b) {
return Math.min(a, b);
}
static int max(int[] a) {
int max = a[0];
for (int i : a)
max = max(max, i);
return max;
}
static int min(int[] a) {
int min = a[0];
for (int i : a)
min = min(min, i);
return min;
}
static long max(long[] a) {
long max = a[0];
for (long i : a)
max = max(max, i);
return max;
}
static long min(long[] a) {
long min = a[0];
for (long i : a)
min = min(min, i);
return min;
}
static int abs(int a) {
return Math.abs(a);
}
static long abs(long a) {
return Math.abs(a);
}
static void yes() throws Exception {
print("Yes");
}
static void no() throws Exception {
print("No");
}
static int[] getarr(List<Integer> list) {
int n = list.size();
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = list.get(i);
return a;
}
public static void main(String[] args) throws Exception {
int T = 1;
//T = get();
while (T-- > 0) {
int[] p = getint();
int n = p[0], k = p[1];
int pre = 0;
int[] f = new int[n+1], ans = new int[n];
f[0] = 1;
for (int i = 1; i <= n; i++) {
int step = (i + k - 1);
pre += step;
for (int j = n; j >= step; j--) f[j] = f[j - step];
for (int j = 0; j < step; j++) f[j] = 0;
for (int j = step; j <= n; j++) f[j] = (f[j] + f[j - step])%mod;
for (int j = step; j <= n; j++) ans[j-1] = (ans[j-1] + f[j])%mod;
if (pre > n)break;
}
print(ans);
}
bw.flush();
}
} | Java | ["8 1", "10 2"] | 2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$, $$$[0, 5]$$$;Ways to reach the point $$$6$$$: $$$[0, 1, 3, 6]$$$, $$$[0, 2, 6]$$$, $$$[0, 4, 6]$$$, $$$[0, 6]$$$;Ways to reach the point $$$7$$$: $$$[0, 2, 4, 7]$$$, $$$[0, 1, 7]$$$, $$$[0, 3, 7]$$$, $$$[0, 5, 7]$$$, $$$[0, 7]$$$;Ways to reach the point $$$8$$$: $$$[0, 3, 5, 8]$$$, $$$[0, 1, 5, 8]$$$, $$$[0, 2, 8]$$$, $$$[0, 4, 8]$$$, $$$[0, 6, 8]$$$, $$$[0, 8]$$$. | Java 11 | standard input | [
"brute force",
"dp",
"math"
] | c5f137635a6c0d1c96b83de049e7414a | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | 2,000 | Print $$$n$$$ integers — the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | standard output | |
PASSED | ea6f5728babf6c0c10c9db4c14790ddf | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class randomfa {
public static void main (String []args){
Scanner sc = new Scanner (System.in);
int a = sc.nextInt();
long []ar = new long[a+1];
int cou=0;
while (a>0){
long b = sc.nextInt();
if(b==1){ar[cou] = 2;
cou++;}
else if (b==2||b==3){ar[cou]=1;
cou++;}
else {
if(b%3==0){
ar[cou] = Math.abs(b/3);
cou++;}
else {ar[cou] = Math.abs(b/3)+1;
cou++;}
}
a--;
}
for(int i = 0 ; ar[i]!=0 ;i++){
System.out.println(ar[i]+"");
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 897abcf0d6406d444b6df6fae074f6e7 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
public class MyClass {
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner(System.in);
int inputCount = sc.nextInt();
int ans = 0;
while(inputCount > 0){
ans = 0;
int point = sc.nextInt();
if(point % 3 == 0){
ans = point/3;
}
else if(point % 3 == 1){
ans = Math.max((point-4), 0)/3 + 2;
}else{
ans = point/3 + 1;
}
System.out.println(ans);
inputCount--;
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 9006ee31c3bcc6e0a1ca271abb001719 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt(), num;
for (int i = 0; i < t; i++)
System.out.println((num = sc.nextInt()) / 3 + (num != 1 ? Math.min(1, num % 3) : 2));
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 052ae2d65f26e0a9a12477ff4e8a13e8 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class Sol {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
// int ar[] = new int[n];
int n =sc.nextInt();
while(n-->0){
int x = sc.nextInt();
sol(x);
}
}
public static void sol(int x){
if(x%3 == 0){
System.out.println(x/3);
}
else if(x%3 == 1){
if(x == 1 || x == 4){
System.out.println(2);
}else{
System.out.println(x/3 + 1);
}
}else if(x%3 == 2){
if(x == 2){
System.out.println(1);
}else{
System.out.println(x/3 + 1);
}
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | ff7f171db73f4f6ec1ab10dbd7685441 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Sol {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
// int ar[] = new int[n];
int n =sc.nextInt();
while(n-->0){
int x = sc.nextInt();
sol(x);
}
}
public static void sol(int x){
if(x%3 == 0){
System.out.println(x/3);
}
else if(x%3 == 1){
if(x == 1 || x == 4){
System.out.println(2);
}else{
System.out.println(x/3 + 1);
}
}else if(x%3 == 2){
if(x == 2){
System.out.println(1);
}else{
System.out.println(x/3 + 1);
}
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | cca5490adfb63c9026730d1c33412b02 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Sol {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
// int ar[] = new int[n];
int n =sc.nextInt();
while(n-->0){
int x = sc.nextInt();
if(x%3 == 0){
System.out.println(x/3);
}
else if(x%3 == 1){
if(x == 1 || x == 4){
System.out.println(2);
}else{
System.out.println(x/3 + 1);
}
}else if(x%3 == 2){
if(x == 2){
System.out.println(1);
}else{
System.out.println(x/3 + 1);
}
}
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | acfa74dac92590fd24611ba49f857c80 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.IOException;
import java.util.*;
public class Certifications {
public static void main(String[] args) throws IOException {
Scanner c = new Scanner(System.in);
int test = c.nextInt(), i = 1, cont = 0;
while (i <= test) {
int number = c.nextInt();
while (number != 0) {
if (number == 2 || number == -2 || number == 4 || number == -4) {
cont += Math.abs(number / 2);
number = number - (number / 2) * 2;
}
if (number > 2 || number < -2) {
String num = number + "";
cont += Math.abs(number / 3)-1;
number = number - ((number / 3)-1) * 3;
if (Integer.parseInt(num) % (Math.max(10, num.length() - 1)) == 4) {
number += 3;
cont--;
}if (number%3==0||number%3==2) {
number+=2;
cont--;
}
}
if (number == 1 || number == -1) {
number = number - 3;
cont++;
}
}
System.out.println(cont);
i++;
cont = 0;
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | b11fb4ffc29ce1a61ab45707a53a6a6a | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | // package com.algorithms;
import java.util.*;
public class Pset18 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int isN = n == 1 ? 1 : 0;
int result = (n <= 3) ? (1 + isN) : (int) Math.floor((n+2)/3);
System.out.println(result);
}
sc.close();
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 3e3bd6bf62c7f834f55b9d4d457b2ae0 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class A_2_3_Moves {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- != 0) {
int n = sc.nextInt();
if (n == 1) {
System.out.println(2);
continue;
}
int ans1 = n / 2;
int ans2 = n / 3;
if (n % 3 != 0)
ans2 += 1;
System.out.println((int) Math.min(ans1, ans2));
}
sc.close();
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 04de326795200eccd8c6915631b58c70 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class A_2_3_Moves {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- != 0) {
int n = sc.nextInt();
if (n == 1) {
System.out.println(2);
continue;
}
int ans1 = n / 2;
if (n % 2 == 1)
ans1 += 1;
int ans2 = n / 3;
if (n % 3 != 0)
ans2 += 1;
System.out.println((int) Math.min(ans1, ans2));
}
sc.close();
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 71884a9b02d13bb6208eaa5d0e9e54e8 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class Moves {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int[] dest = new int[t];
int[] temp = new int[t];
int sum = 0;
for(int i=0;i<t;i++) {
dest[i]=sc.nextInt();
}
for(int i=0;i<t;i++) {
if(dest[i]==1) {
temp[sum]=2;
sum++;
}else if(dest[i]==2) {
temp[sum]=1;
sum++;
}else if(dest[i]%3==0) {
temp[sum]=dest[i]/3;
sum++;
}else if(dest[i]%3==1) {
dest[i]-=4;
temp[sum]=(dest[i]/3)+2;
sum++;
}else if(dest[i]%3==2) {
dest[i]-=2;
temp[sum]=(dest[i]/3)+1;
sum++;
}
}
for(int i=0;i<t;i++) {
System.out.println(temp[i]);
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | af0aa32e729436414259dd23c7305c0e | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import java.lang.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0){
int n = sc.nextInt();
if(n==1)
System.out.println(2);
else if(n%3==0)
System.out.println(n/3);
else if(n%3==1){
if(n%2==0)
System.out.println(Math.min(n/2,n/3+1));
else
System.out.println(n/3+1);
}
else if(n%3==2)
System.out.println(n/3+1);
t-=1;
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 285a601e86a4768171e4070696589ed0 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import static java.lang.Math.max;
import static java.lang.Math.min;
public class A {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while (t-->0) {
int n = scanner.nextInt();
if (n == 1) {
System.out.println(2);
continue;
}
if (n%3==0) {
System.out.println(n/3);
} else {
int ans = 0;
while (n%3!=0) {
n-=2;
ans++;
}
System.out.println(n/3+ans);
}
}
}
private static long sum(int n) {
long sum = 0;
for (int i = 1; i<=n; i++) sum+=i;
return sum;
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 75ce50140bd5ac5222df6f0bd1cdb553 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class New{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0;i<t;i++){
int n = sc.nextInt();
if(n==1){
System.out.println("2");
}
else{
System.out.println((n+2)/3);
}
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 840c634d9cca05c0ede9416c2892c278 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class cls{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
if(n==1){
System.out.println("2");
}
else{
System.out.println((n+2)/3);
}
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | acffa2f69d2dfcfc20cad411ea39f7c1 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class moves2_3 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
System.out.println(steps(n));
}
}
static int steps(int n){
int x=+Math.abs(n);
// if(x==4){
// return 2;
// }
// if(x%3==1 && x!=4){
// return x/3+2;
// }
// else if(x%3==0){
// return x/3;
// }
// return x/3+1;
if(x==2){
return 1;
}
if(x==1) return 2;
else if(x%3==1){
return n/3+1;
}
else if(n%3==2){
return n/3+1;
}
return n/3;
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | c6ec6b361ef58d92ba06a12facfa3203 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class moves23 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in) ;
int t = in.nextInt();
for (int i = 0; i < t; i++){
int n = in.nextInt() ;
if ( n == 1 ) {
System.out.println("2");
continue ;
}
if ( n == 2 ) {
System.out.println("1");
continue ;
}
if ( n % 3 == 0 ) {
System.out.println(n/3);
continue ;
}
System.out.println(n/3 + 1);
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 371ed6dfa004d6efdee023d0bd79456d | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
private static int k=0;
public static void main(String[] args) throws IOException {
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
FastReader fastReader = new FastReader();
int test_cases = fastReader.nextInt();
StringBuilder sb = new StringBuilder();
for(int test=1;test<=test_cases;test++) {
int n = fastReader.nextInt();
sb.append(solve(n)+"\n");
}
output.write(sb.toString());
output.flush();
}
static int solve(int n){
if(n==1){
return 2;
}
if(n%3==0){
return n/3;
}
return n/3+1;
}
static String random(){
StringBuilder sb=new StringBuilder();
int len=3+(int)(Math.random()*10);
for(int i=0;i<len;i++){
sb.append(Math.random()<0.5 ? '0' : '1');
}
return sb.toString();
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 89d8b51c52dda2afb307f63054e5a7be | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Math;
public class Solutions{
public static void main(String args[]) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t= Integer.parseInt(br.readLine());
while(t!=0){
t--;
int n= Integer.parseInt(br.readLine());
if(n==1){
System.out.println(2);
continue;
}
int q=n/3;
if(n%3==0){
System.out.println(q);
}else{
System.out.println(q+1);
}
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 0117f0ce09d82814c5e70ed10c466e05 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class ACMP {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
ArrayList<Integer> ans = new ArrayList<>();
while (t-- > 0) {
int n = sc.nextInt();
if(n==1) {
System.out.println(2);
}else if(n==4){
System.out.println(2);
}else {
int x = n/3;
int y = n%3;
if(y==1){
System.out.println(x+1);
}else if(y==2){
System.out.println(x+1);
}else{
System.out.println(x);
}
}
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | aba084efcff91405b7e1ca4bd6560de9 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
public class Main{
static class InputReader {
/**
* The default size of the InputReader's buffer is 2<sup>16</sup>.
*/
private static final int DEFAULT_BUFFER_SIZE = 1 << 16;
/**
* The default stream for the InputReader is standard input.
*/
private static final InputStream DEFAULT_STREAM = System.in;
/**
* The maximum number of accurate decimal digits the method {@link #nextDoubleFast() nextDoubleFast()} can read.
* Currently this value is set to 21 because it is the maximum number of digits a double precision float can have at the moment.
*/
private static final int MAX_DECIMAL_PRECISION = 21;
// 'c' is used to refer to the current character in the stream
private int c;
// Variables associated with the byte buffer.
private byte[] buf;
private int bufferSize, bufIndex, numBytesRead;
private InputStream stream;
// End Of File (EOF) character
private static final byte EOF = -1;
// New line character: '\n'
private static final byte NEW_LINE = 10;
// Space character: ' '
private static final byte SPACE = 32;
// Dash character: '-'
private static final byte DASH = 45;
// Dot character: '.'
private static final byte DOT = 46;
// A reusable character buffer when reading string data.
private char[] charBuffer;
// Primitive data type lookup tables used for optimizations
private static byte[] bytes = new byte[58];
private static int[] ints = new int[58];
private static char[] chars = new char[128];
static {
char ch = ' ';
int value = 0;
byte _byte = 0;
for (int i = 48; i < 58; i++) bytes[i] = _byte++;
for (int i = 48; i < 58; i++) ints[i] = value++;
for (int i = 32; i < 128; i++) chars[i] = ch++;
}
// Primitive double lookup table used for optimizations.
private static final double[][] doubles = {
{0.0d, 0.00d, 0.000d, 0.0000d, 0.00000d, 0.000000d, 0.0000000d, 0.00000000d, 0.000000000d, 0.0000000000d, 0.00000000000d, 0.000000000000d, 0.0000000000000d, 0.00000000000000d, 0.000000000000000d, 0.0000000000000000d, 0.00000000000000000d, 0.000000000000000000d, 0.0000000000000000000d, 0.00000000000000000000d, 0.000000000000000000000d},
{0.1d, 0.01d, 0.001d, 0.0001d, 0.00001d, 0.000001d, 0.0000001d, 0.00000001d, 0.000000001d, 0.0000000001d, 0.00000000001d, 0.000000000001d, 0.0000000000001d, 0.00000000000001d, 0.000000000000001d, 0.0000000000000001d, 0.00000000000000001d, 0.000000000000000001d, 0.0000000000000000001d, 0.00000000000000000001d, 0.000000000000000000001d},
{0.2d, 0.02d, 0.002d, 0.0002d, 0.00002d, 0.000002d, 0.0000002d, 0.00000002d, 0.000000002d, 0.0000000002d, 0.00000000002d, 0.000000000002d, 0.0000000000002d, 0.00000000000002d, 0.000000000000002d, 0.0000000000000002d, 0.00000000000000002d, 0.000000000000000002d, 0.0000000000000000002d, 0.00000000000000000002d, 0.000000000000000000002d},
{0.3d, 0.03d, 0.003d, 0.0003d, 0.00003d, 0.000003d, 0.0000003d, 0.00000003d, 0.000000003d, 0.0000000003d, 0.00000000003d, 0.000000000003d, 0.0000000000003d, 0.00000000000003d, 0.000000000000003d, 0.0000000000000003d, 0.00000000000000003d, 0.000000000000000003d, 0.0000000000000000003d, 0.00000000000000000003d, 0.000000000000000000003d},
{0.4d, 0.04d, 0.004d, 0.0004d, 0.00004d, 0.000004d, 0.0000004d, 0.00000004d, 0.000000004d, 0.0000000004d, 0.00000000004d, 0.000000000004d, 0.0000000000004d, 0.00000000000004d, 0.000000000000004d, 0.0000000000000004d, 0.00000000000000004d, 0.000000000000000004d, 0.0000000000000000004d, 0.00000000000000000004d, 0.000000000000000000004d},
{0.5d, 0.05d, 0.005d, 0.0005d, 0.00005d, 0.000005d, 0.0000005d, 0.00000005d, 0.000000005d, 0.0000000005d, 0.00000000005d, 0.000000000005d, 0.0000000000005d, 0.00000000000005d, 0.000000000000005d, 0.0000000000000005d, 0.00000000000000005d, 0.000000000000000005d, 0.0000000000000000005d, 0.00000000000000000005d, 0.000000000000000000005d},
{0.6d, 0.06d, 0.006d, 0.0006d, 0.00006d, 0.000006d, 0.0000006d, 0.00000006d, 0.000000006d, 0.0000000006d, 0.00000000006d, 0.000000000006d, 0.0000000000006d, 0.00000000000006d, 0.000000000000006d, 0.0000000000000006d, 0.00000000000000006d, 0.000000000000000006d, 0.0000000000000000006d, 0.00000000000000000006d, 0.000000000000000000006d},
{0.7d, 0.07d, 0.007d, 0.0007d, 0.00007d, 0.000007d, 0.0000007d, 0.00000007d, 0.000000007d, 0.0000000007d, 0.00000000007d, 0.000000000007d, 0.0000000000007d, 0.00000000000007d, 0.000000000000007d, 0.0000000000000007d, 0.00000000000000007d, 0.000000000000000007d, 0.0000000000000000007d, 0.00000000000000000007d, 0.000000000000000000007d},
{0.8d, 0.08d, 0.008d, 0.0008d, 0.00008d, 0.000008d, 0.0000008d, 0.00000008d, 0.000000008d, 0.0000000008d, 0.00000000008d, 0.000000000008d, 0.0000000000008d, 0.00000000000008d, 0.000000000000008d, 0.0000000000000008d, 0.00000000000000008d, 0.000000000000000008d, 0.0000000000000000008d, 0.00000000000000000008d, 0.000000000000000000008d},
{0.9d, 0.09d, 0.009d, 0.0009d, 0.00009d, 0.000009d, 0.0000009d, 0.00000009d, 0.000000009d, 0.0000000009d, 0.00000000009d, 0.000000000009d, 0.0000000000009d, 0.00000000000009d, 0.000000000000009d, 0.0000000000000009d, 0.00000000000000009d, 0.000000000000000009d, 0.0000000000000000009d, 0.00000000000000000009d, 0.000000000000000000009d}
};
/**
* Create an InputReader that reads from standard input.
*/
public InputReader() {
this(DEFAULT_STREAM, DEFAULT_BUFFER_SIZE);
}
/**
* Create an InputReader that reads from standard input.
*
* @param bufferSize The buffer size for this input reader.
*/
public InputReader(int bufferSize) {
this(DEFAULT_STREAM, bufferSize);
}
/**
* Create an InputReader that reads from standard input.
*
* @param stream Takes an InputStream as a parameter to read from.
*/
public InputReader(InputStream stream) {
this(stream, DEFAULT_BUFFER_SIZE);
}
/**
* Create an InputReader that reads from standard input.
*
* @param stream Takes an {@link java.io.InputStream#InputStream() InputStream} as a parameter to read from.
* @param bufferSize The size of the buffer to use.
*/
public InputReader(InputStream stream, int bufferSize) {
if (stream == null || bufferSize <= 0)
throw new IllegalArgumentException();
buf = new byte[bufferSize];
charBuffer = new char[128];
this.bufferSize = bufferSize;
this.stream = stream;
}
/**
* Reads a single character from the input stream.
*
* @return Returns the byte value of the next character in the buffer and EOF
* at the end of the stream.
* @throws IOException throws exception if there is no more data to read
*/
private byte read() throws IOException {
if (numBytesRead == EOF) throw new IOException();
if (bufIndex >= numBytesRead) {
bufIndex = 0;
numBytesRead = stream.read(buf);
if (numBytesRead == EOF)
return EOF;
}
return buf[bufIndex++];
}
/**
* Read values from the input stream until you reach a character with a
* higher ASCII value than 'token'.
*
* @param token The token is a value which we use to stop reading junk out of
* the stream.
* @return Returns 0 if a value greater than the token was reached or -1 if
* the end of the stream was reached.
* @throws IOException Throws exception at end of stream.
*/
private int readJunk(int token) throws IOException {
if (numBytesRead == EOF) return EOF;
// Seek to the first valid position index
do {
while (bufIndex < numBytesRead) {
if (buf[bufIndex] > token) return 0;
bufIndex++;
}
// reload buffer
numBytesRead = stream.read(buf);
if (numBytesRead == EOF) return EOF;
bufIndex = 0;
} while (true);
}
/**
* Reads a single byte from the input stream.
*
* @return The next byte in the input stream
* @throws IOException Throws exception at end of stream.
*/
public byte nextByte() throws IOException {
return (byte) nextInt();
}
/**
* Reads a 32 bit signed integer from input stream.
*
* @return The next integer value in the stream.
* @throws IOException Throws exception at end of stream.
*/
public int nextInt() throws IOException {
if (readJunk(DASH - 1) == EOF) throw new IOException();
int sgn = 1, res = 0;
c = buf[bufIndex];
if (c == DASH) {
sgn = -1;
bufIndex++;
}
do {
while (bufIndex < numBytesRead) {
if (buf[bufIndex] > SPACE) {
res = (res << 3) + (res << 1);
res += ints[buf[bufIndex++]];
} else {
bufIndex++;
return res * sgn;
}
}
// Reload buffer
numBytesRead = stream.read(buf);
if (numBytesRead == EOF) return res * sgn;
bufIndex = 0;
} while (true);
}
/**
* Reads a 64 bit signed long from input stream.
*
* @return The next long value in the stream.
* @throws IOException Throws exception at end of stream.
*/
public long nextLong() throws IOException {
if (readJunk(DASH - 1) == EOF) throw new IOException();
int sgn = 1;
long res = 0L;
c = buf[bufIndex];
if (c == DASH) {
sgn = -1;
bufIndex++;
}
do {
while (bufIndex < numBytesRead) {
if (buf[bufIndex] > SPACE) {
res = (res << 3) + (res << 1);
res += ints[buf[bufIndex++]];
} else {
bufIndex++;
return res * sgn;
}
}
// Reload buffer
numBytesRead = stream.read(buf);
if (numBytesRead == EOF) return res * sgn;
bufIndex = 0;
} while (true);
}
/**
* Doubles the size of the internal char buffer for strings
*/
private void doubleCharBufferSize() {
char[] newBuffer = new char[charBuffer.length << 1];
for (int i = 0; i < charBuffer.length; i++) newBuffer[i] = charBuffer[i];
charBuffer = newBuffer;
}
/**
* Reads a line from the input stream.
*
* @return Returns a line from the input stream in the form a String not
* including the new line character. Returns <code>null</code> when there are
* no more lines.
* @throws IOException Throws IOException when something terrible happens.
*/
public String nextLine() throws IOException {
try {
c = read();
} catch (IOException e) {
return null;
}
if (c == NEW_LINE) return ""; // Empty line
if (c == EOF) return null; // EOF
int i = 0;
charBuffer[i++] = (char) c;
do {
while (bufIndex < numBytesRead) {
if (buf[bufIndex] != NEW_LINE) {
if (i == charBuffer.length) doubleCharBufferSize();
charBuffer[i++] = (char) buf[bufIndex++];
} else {
bufIndex++;
return new String(charBuffer, 0, i);
}
}
// Reload buffer
numBytesRead = stream.read(buf);
if (numBytesRead == EOF)
return new String(charBuffer, 0, i);
bufIndex = 0;
} while (true);
}
// Reads a string of characters from the input stream.
// The delimiter separating a string of characters is set to be:
// any ASCII value <= 32 meaning any spaces, new lines, EOF, tabs...
public String nextString() throws IOException {
if (numBytesRead == EOF) return null;
if (readJunk(SPACE) == EOF) return null;
for (int i = 0; ; ) {
while (bufIndex < numBytesRead) {
if (buf[bufIndex] > SPACE) {
if (i == charBuffer.length) doubleCharBufferSize();
charBuffer[i++] = (char) buf[bufIndex++];
} else {
bufIndex++;
return new String(charBuffer, 0, i);
}
}
// Reload buffer
numBytesRead = stream.read(buf);
if (numBytesRead == EOF) return new String(charBuffer, 0, i);
bufIndex = 0;
}
}
// Returns an exact value a double value from the input stream.
public double nextDouble() throws IOException {
String doubleVal = nextString();
if (doubleVal == null) throw new IOException();
return Double.valueOf(doubleVal);
}
// Very quickly reads a double value from the input stream (~3x faster than nextDouble()). However,
// this method may provide a slightly less accurate reading than .nextDouble() if there are a lot
// of digits (~16+). In particular, it will only read double values with at most 21 digits after
// the decimal point and the reading my be as inaccurate as ~5*10^-16 from the true value.
public double nextDoubleFast() throws IOException {
c = read();
int sgn = 1;
while (c <= SPACE) c = read(); // while c is either: ' ', '\n', EOF
if (c == DASH) {
sgn = -1;
c = read();
}
double res = 0.0;
// while c is not: ' ', '\n', '.' or -1
while (c > DOT) {
res *= 10.0;
res += ints[c];
c = read();
}
if (c == DOT) {
int i = 0;
c = read();
// while c is digit and we are less than the maximum decimal precision
while (c > SPACE && i < MAX_DECIMAL_PRECISION) {
res += doubles[ints[c]][i++];
c = read();
}
}
return res * sgn;
}
// Read an array of n byte values
public byte[] nextByteArray(int n) throws IOException {
byte[] ar = new byte[n];
for (int i = 0; i < n; i++) ar[i] = nextByte();
return ar;
}
// Read an integer array of size n
public int[] nextIntArray(int n) throws IOException {
int[] ar = new int[n];
for (int i = 0; i < n; i++) ar[i] = nextInt();
return ar;
}
// Read a long array of size n
public long[] nextLongArray(int n) throws IOException {
long[] ar = new long[n];
for (int i = 0; i < n; i++) ar[i] = nextLong();
return ar;
}
// read an of doubles of size n
public double[] nextDoubleArray(int n) throws IOException {
double[] ar = new double[n];
for (int i = 0; i < n; i++) ar[i] = nextDouble();
return ar;
}
// Quickly read an array of doubles
public double[] nextDoubleArrayFast(int n) throws IOException {
double[] ar = new double[n];
for (int i = 0; i < n; i++) ar[i] = nextDoubleFast();
return ar;
}
// Read a string array of size n
public String[] nextStringArray(int n) throws IOException {
String[] ar = new String[n];
for (int i = 0; i < n; i++) {
String str = nextString();
if (str == null) throw new IOException();
ar[i] = str;
}
return ar;
}
// Read a 1-based byte array of size n+1
public byte[] nextByteArray1(int n) throws IOException {
byte[] ar = new byte[n + 1];
for (int i = 1; i <= n; i++) ar[i] = nextByte();
return ar;
}
// Read a 1-based integer array of size n+1
public int[] nextIntArray1(int n) throws IOException {
int[] ar = new int[n + 1];
for (int i = 1; i <= n; i++) ar[i] = nextInt();
return ar;
}
// Read a 1-based long array of size n+1
public long[] nextLongArray1(int n) throws IOException {
long[] ar = new long[n + 1];
for (int i = 1; i <= n; i++) ar[i] = nextLong();
return ar;
}
// Read a 1-based double array of size n+1
public double[] nextDoubleArray1(int n) throws IOException {
double[] ar = new double[n + 1];
for (int i = 1; i <= n; i++) ar[i] = nextDouble();
return ar;
}
// Quickly read a 1-based double array of size n+1
public double[] nextDoubleArrayFast1(int n) throws IOException {
double[] ar = new double[n + 1];
for (int i = 1; i <= n; i++) ar[i] = nextDoubleFast();
return ar;
}
// Read a 1-based string array of size n+1
public String[] nextStringArray1(int n) throws IOException {
String[] ar = new String[n + 1];
for (int i = 1; i <= n; i++) ar[i] = nextString();
return ar;
}
// Read a two dimensional matrix of bytes of size rows x cols
public byte[][] nextByteMatrix(int rows, int cols) throws IOException {
byte[][] matrix = new byte[rows][cols];
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
matrix[i][j] = nextByte();
return matrix;
}
// Read a two dimensional matrix of ints of size rows x cols
public int[][] nextIntMatrix(int rows, int cols) throws IOException {
int[][] matrix = new int[rows][cols];
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
matrix[i][j] = nextInt();
return matrix;
}
// Read a two dimensional matrix of longs of size rows x cols
public long[][] nextLongMatrix(int rows, int cols) throws IOException {
long[][] matrix = new long[rows][cols];
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
matrix[i][j] = nextLong();
return matrix;
}
// Read a two dimensional matrix of doubles of size rows x cols
public double[][] nextDoubleMatrix(int rows, int cols) throws IOException {
double[][] matrix = new double[rows][cols];
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
matrix[i][j] = nextDouble();
return matrix;
}
// Quickly read a two dimensional matrix of doubles of size rows x cols
public double[][] nextDoubleMatrixFast(int rows, int cols) throws IOException {
double[][] matrix = new double[rows][cols];
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
matrix[i][j] = nextDoubleFast();
return matrix;
}
// Read a two dimensional matrix of Strings of size rows x cols
public String[][] nextStringMatrix(int rows, int cols) throws IOException {
String[][] matrix = new String[rows][cols];
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
matrix[i][j] = nextString();
return matrix;
}
// Read a 1-based two dimensional matrix of bytes of size rows x cols
public byte[][] nextByteMatrix1(int rows, int cols) throws IOException {
byte[][] matrix = new byte[rows + 1][cols + 1];
for (int i = 1; i <= rows; i++)
for (int j = 1; j <= cols; j++)
matrix[i][j] = nextByte();
return matrix;
}
// Read a 1-based two dimensional matrix of ints of size rows x cols
public int[][] nextIntMatrix1(int rows, int cols) throws IOException {
int[][] matrix = new int[rows + 1][cols + 1];
for (int i = 1; i <= rows; i++)
for (int j = 1; j <= cols; j++)
matrix[i][j] = nextInt();
return matrix;
}
// Read a 1-based two dimensional matrix of longs of size rows x cols
public long[][] nextLongMatrix1(int rows, int cols) throws IOException {
long[][] matrix = new long[rows + 1][cols + 1];
for (int i = 1; i <= rows; i++)
for (int j = 1; j <= cols; j++)
matrix[i][j] = nextLong();
return matrix;
}
// Read a 1-based two dimensional matrix of doubles of size rows x cols
public double[][] nextDoubleMatrix1(int rows, int cols) throws IOException {
double[][] matrix = new double[rows + 1][cols + 1];
for (int i = 1; i <= rows; i++)
for (int j = 1; j <= cols; j++)
matrix[i][j] = nextDouble();
return matrix;
}
// Quickly read a 1-based two dimensional matrix of doubles of size rows x cols
public double[][] nextDoubleMatrixFast1(int rows, int cols) throws IOException {
double[][] matrix = new double[rows + 1][cols + 1];
for (int i = 1; i <= rows; i++)
for (int j = 1; j <= cols; j++)
matrix[i][j] = nextDoubleFast();
return matrix;
}
// Read a 1-based two dimensional matrix of Strings of size rows x cols
public String[][] nextStringMatrix1(int rows, int cols) throws IOException {
String[][] matrix = new String[rows + 1][cols + 1];
for (int i = 1; i <= rows; i++)
for (int j = 1; j <= cols; j++)
matrix[i][j] = nextString();
return matrix;
}
// Closes the input stream
public void close() throws IOException {
stream.close();
}
}
public static InputReader read = new InputReader();
public static void main(String[] args) throws IOException {
int t = read.nextInt();
while(t-- != 0){
int n = read.nextInt(), x= 0;
x = n%3 == 0? n/3 :(int)Math.ceil(n/3) + 1;
System.out.println(n==1?2 :x);
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | e927055b946043cfaa856dcc1c329c40 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
var in = new Scanner(System.in);
var tests = in.nextInt();
while (tests-->0){
var n = Math.abs(in.nextInt());
var count = 0;
if(n%3==0) count = n/3;
else if (n%3==1) {
count = (n/3==0 ? n/3 : n/3-1) + 2;
}
else count = n/3 + 1;
System.out.println(count);
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | ce58c7aef825d68d716f4bf814df640f | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class problemA{
public static void main(String[] args) {
Scanner sh = new Scanner(System.in);
int t = sh.nextInt();
while(t>0){
int n = sh.nextInt();
int min = 1000000001;
if(n%3 == 0){
min = Math.min(min, n/3);
}
if(n%2==0){
min = Math.min(min,n/2);
}
if(n%3==1 && n!=1){
min = Math.min(min,1 + (n)/3);
}
if(n%3==1 && n==1){
min = Math.min(min,1 + (n+2)/3);
}
if(n%3==2){
min = Math.min(min,1+(n)/3);
}
System.out.println(min);
t--;}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 9edf46a7615d7d8e1f8060028c9668b1 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution {
// DO NOT MODIFY THE LIST. IT IS READ ONLY
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
int[] answer = new int[t];
for(int i = 0; i < t; i++){
int n = Integer.parseInt(br.readLine());
answer[i] = solve(n);
}
for(int i : answer)
System.out.println(i);
}
public static int solve(int n){
if(n == 1) return 2;
if(n % 3 == 0) return n / 3;
else if (n % 3 == 2) return n / 3 + 1;
else {
return n / 3 + 1;
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | b605a480a7b3461c7a34cece37719da5 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class Moves{
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int test = sc.nextInt();
int arr[] = new int[test];
for(int i=0;i<test;i++)
{
int n = sc.nextInt();
int ans = 0;
if(n % 3 == 0)
ans = n/3;
else if(n % 3 == 2)
ans = (n/3)+1;
else if(n % 3 == 1)
{
if(n == 1)
ans = 2;
else
ans = (n-4)/3 + 2;
}
arr[i] = ans;
}
for(int i : arr)
out.println(i);
out.close();
}
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 65cca8658fc525abd5ce7bf37d7a9d5e | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
while (t > 0) {
t--;
int result = solve(input.nextInt());
System.out.println(result);
}
input.close();
}
private static int solve(int n) {
if (n % 3 == 0) return n / 3;
if (n == 1) return 2;
int moves3 = n / 3;
n -= moves3 * 3;
if (n == 1 || n == 2) return moves3 + 1;
return moves3;
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | b85835a09e3dc974527bf07c516ec47a | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.lang.*;
import java.lang.Exception;
import java.math.BigInteger;
import java.util.*;
public class Main {
private static final BufferedWriter sout = new BufferedWriter(new OutputStreamWriter(System.out));
private static final double PI = 3.141592653;
public static int lowerBoundIndex(int[] arr, int key) {
// Arrays.sort(arr);
int idx = Arrays.binarySearch(arr, key);
if (idx >= 0) {
return idx;
} else if ((idx + 1) * -1 < arr.length && (idx + 1) * -1 >= 0) return (idx + 1) * -1;
return -1;
}
public static int lowerBoundElement(int[] arr, int key) {
// Arrays.sort(arr);
int idx = Arrays.binarySearch(arr, key);
if (idx >= 0) {
return arr[idx];
} else if ((idx + 1) * -1 < arr.length && (idx + 1) * -1 >= 0) return arr[(idx + 1) * -1];
return -1;
}
public static int upperBoundElement(int[] arr, int key) {
int idx = Arrays.binarySearch(arr, key);
if ((idx + 1) < arr.length && idx >= 0) {
return arr[idx + 1];
} else if ((idx + 1) * -1 < arr.length && (idx + 1) * -1 >= 0) return arr[(idx + 1) * -1];
return -1;
}
public static int upperBoundIndex(int[] arr, int key) {
int idx = Arrays.binarySearch(arr, key);
if ((idx + 1) < arr.length && idx >= 0) {
return idx + 1;
} else if ((idx + 1) * -1 < arr.length && (idx + 1) * -1 >= 0) return (idx + 1) * -1;
return -1;
}
public static boolean prime(int n) {
if (n == 1)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (int i = 3; i * i <= n; i += 2)
if (n % i == 0)
return false;
return true;
}
//-------------------------------------------------------------------------------------------------------------------//
public static void main(String[] argus) throws IOException {
Flash flash = new Flash(System.in);
int t= flash.nextInt();
for(int i=0;i<t;i++){
int x= flash.nextInt();
List<Integer> l=new ArrayList<>();
if(x==1)sout.write(2+"\n");
else{
if(x%3==0){
l.add(x/3);
if((x-2)%3==0){
x-=2;
l.add((x/3)+1);
x+=2;
}
if((x-3)%2==0) {
x-=3;
l.add((x/2)+1);
x+=3;
}
if((x+3)%2==0)l.add((x+3)/2);
if((x+3)%3==0)l.add((x+3)/3);
if((x+2)%2==0)l.add((x+2)/2);
if((x+2)%3==0)l.add((x+2)/3);
sout.write(Collections.min(l)+"\n");
}
else if(x%2==0){
l.add(x/2);
if((x-2)%3==0){
x-=2;
l.add((x/3)+1);
x+=2;
}
if((x-3)%2==0){
x-=3;
l.add((x/2)+1);
x+=3;
}
if((x+3)%2==0)l.add((x+3)/2);
if((x+3)%3==0)l.add((x+3)/3);
if((x+2)%2==0)l.add((x+2)/2);
if((x+2)%3==0)l.add((x+2)/3);
sout.write(Collections.min(l)+"\n");
}
else{
if((x-2)%3==0){
x-=2;
l.add((x/3)+1);
x+=2;
}
if((x-3)%2==0){
x-=3;
l.add((x/2)+1);
x+=3;
}
if((x+3)%2==0)l.add((x+3)/2);
if((x+3)%3==0)l.add((x+3)/3);
if((x+2)%2==0)l.add((x+2)/2);
if((x+2)%3==0)l.add((x+2)/3);
sout.write(Collections.min(l)+"\n");
}
}
}
sout.flush();
}
//------------------------------------------------------------------------------------------------------------------//
}
/* *****to iterate through a map*****
for(Map.Entry<String, Integer> entry:map.entrySet()){}
*/
class Pair{
List<Integer> pos;
List<Integer> value;
public Pair(List<Integer> pos, List<Integer> value) {
this.pos=pos;
this.value=value;
}
public List<Integer> getLeft() {
return this.pos;
}
public List<Integer> getRight() {
return this.value;
}
public void setLeft(List<Integer> pos) {
this.pos=pos;
}
public void setRight(List<Integer> value) {
this.value=value;
}
public static void toString(List<Pair> pairs) {
for (int i = 0; i < pairs.size(); i++) {
System.out.print(pairs.get(i).getLeft() + " " + pairs.get(i).getRight());
System.out.println();
}
}
}
//7 7 6 4 2 2
//don't get panic, it's just speed code :)
class Flash {
StringTokenizer st;
BufferedReader br;
public Flash(File file) throws FileNotFoundException {
br = new BufferedReader(new FileReader(file));
}
public Flash(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public int[] intArr(int n) throws IOException {
int[] in = new int[n];
for (int i = 0; i < in.length; i++) in[i] = nextInt();
return in;
}
public long[] longArr(int n) throws IOException {
long[] in = new long[n];
for (int i = 0; i < in.length; i++) in[i] = nextLong();
return in;
}
public int[] intSortedArr(int n) throws IOException {
int[] in = new int[n];
for (int i = 0; i < in.length; i++) in[i] = nextInt();
shuffle(in);
Arrays.sort(in);
return in;
}
public long[] longSortedArr(int n) throws IOException {
long[] in = new long[n];
for (int i = 0; i < in.length; i++) in[i] = nextLong();
shuffle(in);
Arrays.sort(in);
return in;
}
static void shuffle(int[] in) {
for (int i = 0; i < in.length; i++) {
int idx = (int) (Math.random() * in.length);
int tmp = in[i];
in[i] = in[idx];
in[idx] = tmp;
}
}
static void shuffle(long[] in) {
for (int i = 0; i < in.length; i++) {
int idx = (int) (Math.random() * in.length);
long tmp = in[i];
in[i] = in[idx];
in[idx] = tmp;
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 3ce54dc7656acd752ee27610216828d9 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes |
import java.util.Scanner;
public class Moves {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int testCase = input.nextInt();
int num = 0;
int result = 0;
while(testCase-- > 0){
num = Math.abs(input.nextInt());
result=0;
// 169102654
switch (num) {
case 1:
result = 2;
break;
case 2:
result =1;
break;
default:
switch (num%3) {
case 1:
result = (num/3) + 1;
break;
case 2:
result = (num/3) + 1;
break;
case 0:
result = num/3;
break;
default:
break;
} break;
}
System.out.println(result);
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | dafd30d2544eb50840d84b81124fe576 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class Main {
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int num = scanner.nextInt();
while(num-- > 0){
test_case();
}
}
private static void test_case() {
int n = scanner.nextInt();
if (n == 1) System.out.println(2);
else if (n % 3 == 0) System.out.println(n/3);
else System.out.println(n/3+1);
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | b3d3876d9417d3b508de45a7f0c0f83b | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes |
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;
public class Test1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
if (n == 1) {
System.out.println(2);
continue;
}
if (n % 3 == 0) {
System.out.println(n / 3);
continue;
} else {
System.out.println(n / 3 + 1);
continue;
}
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 11d806b8b6ea25f9ccf159ed32f04599 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class solution{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0){
int n = sc.nextInt();
if (n == 1){
System.out.println(2);
}
else if (n % 3 == 0){
System.out.println(n/3);
}
else{
System.out.println((n/3) + 1);
}
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 948eb88f85cd84c53d70de4ecb528e46 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Solution {
public static long findSteps(long n) {
if(n == 0)
return 0;
if(n == 1)
return 2;
return (n % 3 == 0 ? n / 3 : n / 3 + 1);
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while(t > 0) {
long n = scan.nextLong();
System.out.println(findSteps(n));
t--;
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 084c4f21fc736a59ab0bd3e22f1aabab | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int count = scanner.nextInt();
for (int i = 0; i < count; i++) {
System.out.println(solution(scanner.nextInt()));
}
}
public static int solution(int x) {
if (x == 0) {
return 0;
}
if (x < 0) {
x *= -1;
}
if (x == 1) {
return 2;
} else if (x == 2 || x == 3) {
return 1;
}
if (x % 3 == 0) {
return x / 3;
}
return x / 3 + 1;
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | ead15ec4a88e5799953465bb1601ca3a | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | /*--------
Author : Ryan Ranaut
__Hope is a big word, never lose it__
----------*/
import java.io.*;
import java.util.*;
public class Codechef1 {
static PrintWriter out = new PrintWriter(System.out);
static final int mod = 1_000_000_007;
static final long max = (int) (1e18);
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long[] readLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
/*--------------------------------------------------------------*/
//Try seeing general case
//If WA...try using long
//Try for smallest input
public static void main(String[] args)
{
FastReader s = new FastReader();
int t = s.nextInt();
while(t-->0)
{
int n = s.nextInt();
out.println(find(n));
}
out.close();
}
public static int find(int n)
{
if(n == 1)
return 2;
int rem = n%3;
if(rem == 0)
return n/3;
return n/3+1;
}
/*----------------End of the road-------------------*/
static class DSU {
int[] parent;
int[] ranks;
int[] groupSize;
int size;
public DSU(int n) {
size = n;
parent = new int[n];//0 based
ranks = new int[n];
groupSize = new int[n];//Size of each component
for (int i = 0; i < n; i++) {
parent[i] = i;
ranks[i] = 1; groupSize[i] = 1;
}
}
public int find(int x)//Path Compression
{
if (parent[x] == x)
return x;
else
return parent[x] = find(parent[x]);
}
public void union(int x, int y)//Union by rank
{
int x_rep = find(x);
int y_rep = find(y);
if (x_rep == y_rep)
return;
if (ranks[x_rep] < ranks[y_rep])
{
parent[x_rep] = y_rep;
groupSize[y_rep] += groupSize[x_rep];
}
else if (ranks[x_rep] > ranks[y_rep])
{
parent[y_rep] = x_rep;
groupSize[x_rep] += groupSize[y_rep];
}
else {
parent[y_rep] = x_rep;
ranks[x_rep]++;
groupSize[x_rep] += groupSize[y_rep];
}
size--;//Total connected components
}
}
public static int gcd(int x,int y)
{
return y==0?x:gcd(y,x%y);
}
public static long gcd(long x,long y)
{
return y==0L?x:gcd(y,x%y);
}
public static int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
public static long pow(long a,long b)
{
if(b==0L)
return 1L;
long tmp=1;
while(b>1L)
{
if((b&1L)==1)
tmp*=a;
a*=a;
b>>=1;
}
return (tmp*a);
}
public static long modPow(long a,long b,long mod)
{
if(b==0L)
return 1L;
long tmp=1;
while(b>1L)
{
if((b&1L)==1L)
tmp*=a;
a*=a;
a%=mod;
tmp%=mod;
b>>=1;
}
return (tmp*a)%mod;
}
static long mul(long a, long b) {
return a*b%mod;
}
static long fact(int n) {
long ans=1;
for (int i=2; i<=n; i++) ans=mul(ans, i);
return ans;
}
static long fastPow(long base, long exp) {
if (exp==0) return 1;
long half=fastPow(base, exp/2);
if (exp%2==0) return mul(half, half);
return mul(half, mul(half, base));
}
static void debug(int ...a)
{
for(int x: a)
out.print(x+" ");
out.println();
}
static void debug(long ...a)
{
for(long x: a)
out.print(x+" ");
out.println();
}
static void debugMatrix(int[][] a)
{
for(int[] x:a)
out.println(Arrays.toString(x));
}
static void debugMatrix(long[][] a)
{
for(long[] x:a)
out.println(Arrays.toString(x));
}
static void reverseArray(int[] a) {
int n = a.length;
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
static void reverseArray(long[] a) {
int n = a.length;
long[] arr = new long[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
static void sort(int[] a)
{
ArrayList<Integer> ls = new ArrayList<>();
for(int x: a) ls.add(x);
Collections.sort(ls);
for(int i=0;i<a.length;i++)
a[i] = ls.get(i);
}
static void sort(long[] a)
{
ArrayList<Long> ls = new ArrayList<>();
for(long x: a) ls.add(x);
Collections.sort(ls);
for(int i=0;i<a.length;i++)
a[i] = ls.get(i);
}
static class Pair{
int x, y;
Pair(int x, int y)
{
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pair = (Pair) o;
return x == pair.x && y == pair.y;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | e82016c3f8befd969dd664ceb0b15ccc | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Main{
static int Minimum(int a, int b){
if(a<b) return a;
return b;
}
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int t=sc.nextInt();
while(t>0){
t-=1;
int n=sc.nextInt();
int ans=n/3;
int kans=n/2;
if(n%3>0) ans++;
ans=Minimum(ans, kans);
if(n==1) ans=2;
System.out.println(ans);
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 85aac78994032d4fe155c602b1e272b5 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t;
t=sc.nextInt();
int num;
int temp;
for(int i=0; i<t; i++){
num=sc.nextInt();
if(num==1){
System.out.println(2);
}
else if(num%2==0 && num%3==0){
System.out.println(num/3);
}
else if(num%3==0 || num==4){
if(num==4){
System.out.println(2);
}
else{
System.out.println(num/3);
}
}
else{
temp = num/3;
if(num-temp==2){
System.out.println(temp+1);
}
else{
System.out.println(temp+1);
}
}
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 2d3108d425e011c958359575e0b0c63f | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class main {
public static void main(String args[] ) throws Exception {
Scanner in=new Scanner(System.in);
for(int t=in.nextInt();t>0;t--){
int n=in.nextInt();
if(n==1)System.out.println(2);
else System.out.println((n+2)/3);
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | a5eb7390946e857ce5aa2675a6fd52e2 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class main {
public static void main(String args[] ) throws Exception {
Scanner in=new Scanner(System.in);
for(int t=in.nextInt();t>0;t--){
int n=in.nextInt();
if(n==1)System.out.println(2);
else System.out.println((int)Math.ceil((double)n/3));
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 8091f728eb9ff907fb304874715952b7 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static void solve() throws Exception{
//read for each testcase line b line ysing bf reader
st = new StringTokenizer(bf.readLine());
int n = Integer.parseInt(st.nextToken());
int rem = n%3;
int ans = 0;
if(n==0) ans=0;
else if(n==1) ans = 2;
else if(n==2) ans = 1;
else if(rem==0){
ans = n/3;
}else if(rem==1){
//fill 2*2 first
//if(n==4) System.out.println("SSLD"+n+":"+rem);
n-=4;
ans+=2;
if(n>0) ans += (n/3);
}else if(rem==2){
ans = (n-2)/3+1;
}
System.out.println(ans);
}
//Boiler Code
static BufferedReader bf;
static StringTokenizer st;
public static void main(String args[]) throws Exception{
bf = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(bf.readLine());
int n = Integer.parseInt(st.nextToken());
// int n = 1;
while(n-->0){
solve();
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 52aa5e8e63a3bad779c05825413a5707 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Main{
public static void main(String [] args){
Scanner sc= new Scanner(System.in);
int t= sc.nextInt();
while(t-->0){
int n= sc.nextInt();
int count=0;
//int t= sc.nextInt();
int s=0;
if(n%3==0){
s=n/3;
}
else if(n==1){
s=2;
}
else {
int a=n;
s=0;
while(a%2!=0){
a=a-3;
count++;
}
int s1=a/2+count;
a=n;
int s2=0; count=0;
while(a%3!=0){
a=a-2;
count++;
}
s2=a/3+count;
s= Math.min(s1,s2);
}
System.out.println(s);
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 0396049fbaf28d525a42c9fbed8db639 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i = 0 ; i < t ; i++) {
int x = sc.nextInt();
if(x == 1){
System.out.println(2);
}
else{
while(x % 3 != 0){
x++;
}
System.out.println(x / 3);
}
}
sc.close();
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 78b5337be2eff40efbf766f9a4211f04 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Timepass {
public static int calc(int x) {
int k=x/6;
if (x == 1) {
return 2;
}
if(x%6==0){
return 2*k;
}
else if(x%6<=2){
return (2*(k-1))+3;
}
else if(x%6==3){
return (2*k)+1;
}else{
return (2*k)+2;
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t>0) {
int x=sc.nextInt();
System.out.println(calc(Math.abs(x)));
t--;
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | c33d30c07873b5ba1f6f0810485bbb2e | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class ProblemA {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt(); // Number of test cases.
while(t > 0){
long n = sc.nextInt(); // Number of inputs.
if(n == 1){
System.out.println(2);
} else if(n%3 == 0){
System.out.println(n/3);
} else if(n%3 == 1){
System.out.println(((n-1)/3) + 1);
} else if(n%3 == 2){
System.out.println(((n-2)/3) + 1);
} t--;
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | ac68b54e642b6ea564ce4d9c28254117 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class Solution {
public static void main(String k[]) {
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();
while (tc-- > 0) {
long r = sc.nextLong();
if (r % 3 == 0)
System.out.println(r / 3);
else if (r % 3 == 1)
if(r==1)
System.out.println(r / 3 + 2);
else
System.out.println(r / 3 + 1);
else if (r % 3 == 2)
System.out.println(r / 3 + 1);
else if (r % 2 == 0)
System.out.println(r / 2);
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | d218e95b651cc912f8d59139119db8bf | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.PriorityQueue;
import java.util.Scanner;
public class oooo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int i=0;
i=n/3;
if(n%3!=0)
i++;
if(n==1)
i++;
System.out.println(i);
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | c151d94e6f04e23dbe753bc02ec73293 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while (t > 0) {
t--;
int n = scanner.nextInt();
if (n == 1) {
System.out.println(2);
continue;
}
int stepsA = n / 2;
if (n % 2 == 1) {
stepsA += 2;
}
int stepsB = n / 3;
if (n % 3 == 1) {
stepsB += 1;
} else if (n % 3 == 2) {
stepsB += 1;
}
System.out.println(Math.min(stepsA, stepsB));
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 829c4b825efb50e2f4c631123b9ba87f | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class P1 {
static class FastReader {
BufferedReader br;
StringTokenizer st;
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
int nextInt() { return Integer.parseInt(next()); }
}
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t>0) {
int n = sc.nextInt();
if(n == 1)System.out.println(2);
else if(n == 4)System.out.println(2);
else if(n % 3 == 0)System.out.println(n/3);
else if(n % 3 == 1) {
int k = n - 3;
int ans = k/3;
ans+=2;
System.out.println(ans);
}else {
int ans = n/3;
ans+= 1;
System.out.println(ans);
}
t--;
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 4c383e93fabc26914f1c975dd85ca44c | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.math.BigInteger;
import java.util.*;
public class P1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0) {
int n = sc.nextInt();
if(n == 1)System.out.println(2);
else if(n == 4)System.out.println(2);
else if(n % 3 == 0)System.out.println(n/3);
else if(n % 3 == 1) {
int k = n - 3;
int ans = k/3;
ans+=2;
System.out.println(ans);
}else {
int ans = n/3;
ans+= 1;
System.out.println(ans);
}
t--;
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 4ceef5b55bec667cbd447b825a116a04 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Codechef {
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static PrintWriter pw = new PrintWriter(System.out);
private static Scanner sc = new Scanner(System.in);
static void getRes() throws Exception {
long n = Long.parseLong(br.readLine());
long res = n/3, rem = n % 3;
if (rem == 2 || (rem == 1 && res > 0)) res++;
else if (rem == 1) res += 2;
pw.println(res);
}
public static void main(String[] args) throws Exception {
int tests = Integer.parseInt(br.readLine());
while (tests-- > 0) {
getRes();
}
pw.flush();
pw.close();
}
static int[] inputIntArray(int n) throws Exception {
int[] arr = new int[n];
String[] inp = br.readLine().split(" ");
for (int x = 0; x < n; x++)
arr[x] = Integer.parseInt(inp[x]);
return arr;
}
static long[] inputLongArray(int n) throws Exception {
long[] arr = new long[n];
String[] inp = br.readLine().split(" ");
for (int x = 0; x < n; x++)
arr[x] = Integer.parseInt(inp[x]);
return arr;
}
static void printArray(int[] arr) {
for (int x = 0; x < arr.length; x++)
pw.print(arr[x] + " ");
pw.println();
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 77d0cd296513a1d15e1acd63d99473c4 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
for (int i = 0 ; i < t; i++)
{
int n = input.nextInt();
if (n==1)
System.out.println(2);
else if(n%3==0)
System.out.println((n/3));
else
System.out.println((n/3)+1);
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 5f96cf7344520ad5d70529899546b42d | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes |
// import java.lang.reflect.Array
import java.util.*;
public class Solution {
static int n, p;
public static int average(int p) {
int t = 0;
if (p == 1) {
t = 2;
} else if (p == 2) {
t = 1;
} else if (p % 3 == 1 || p % 3 == 2) {
t = (p / 3) + 1;
} else if (p % 3 == 0) {
t = p/3;
}
return t;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
p = sc.nextInt();
System.out.println(+average(p));
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 53d3376df039e27cc1c42e9d0a3b67ef | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
for(int i = 0; i < n; i++)
{
int num = scan.nextInt();
int rem = num/3;
if(num == 1) System.out.println(2);
else if(num%3 > 0) System.out.println((rem+1));
else System.out.println(rem);
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | f7587497cded6b1d142e10c82705975b | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class A1716 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while(t>0){
int n = scanner.nextInt();
int minMinutes = getMinMinutes(n);
System.out.println(minMinutes);
t--;
}
}
private static int getMinMinutes(int n) {
if(n==1) return 2;
if(n==2) return 1;
if(n%3 == 0) return n/3;
else return n/3 + 1;
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 302fc2b86b33e3517d123343fbc629ba | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class Moves {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
if(n==1)
System.out.println("2");
else if(n%3==1)
System.out.println((n+2)/3);
else if(n%3==2)
System.out.println((n+1)/3);
else
System.out.println(n/3);
}
sc.close();
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | e0c1dbeef9d512a57c36654043a90f2d | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Main
{
static int dp[];
static int fun(int n){
if(n==0)return 0;
if(n<0) return 1;
if(dp[n]!=(-1)) return dp[n];
return dp[n]=Math.min(fun(n-3)+1,fun(n-2)+1);
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(--t>=0){
int n=sc.nextInt();
if(n>=10){
if(n%3!=0) System.out.println((n/3)+1);
if(n%3==0) System.out.println(n/3);
continue;
}
dp=new int[n+1];
Arrays.fill(dp,-1);
System.out.println(fun(n));
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | d2fc4021ac23f1d593bbb45ba2ab660c | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.Scanner;
public class Codeforces {
public static void main(String[] args) {
Scanner lta = new Scanner(System.in);
int t = lta.nextInt();
while (t -->0){
int n = lta.nextInt();
int min = 0;
if (n < 2){
System.out.println(2);
}
else {
System.out.println((int)Math.ceil((double)n/3));
}
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 2aff27084f640b2adbdf318e868df47f | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution {
private static final SuperFastReader sc = new SuperFastReader();
private static final int MOD = (int) (1e9) + 7;// ((a + b) % MOD + MOD) % MOD
public static void main(String[] args) throws IOException {
int t = sc.Int();
for (int i = 1; i <= t; ++i) {
// System.out.print("Case #" + i + ": ");
solve();
}
// solve();
sc.close();
}
public static void solve() throws IOException {
long n = sc.Long();
if(n == 1){
System.out.println(2);
return;
}
if(n % 3 == 0){
System.out.println(n / 3);
}
else if(n % 3 == 2){
System.out.println(n / 3 + 1);
}
else{
System.out.println((n - 4) / 3 + 2);
}
}
}
class Pair<K, V> {
public K key;
public V value;
Pair(K k, V v) {
key = k;
value = v;
}
}
class SuperFastReader extends PrintWriter {
private InputStream stream;
private byte[] buf = new byte[1 << 16];
private int curChar, numChars;
// standard input
public SuperFastReader() {
this(System.in, System.out);
}
public SuperFastReader(InputStream i, OutputStream o) {
super(o);
stream = i;
}
// file input
public SuperFastReader(String i, String o) throws IOException {
super(new FileWriter(o));
stream = new FileInputStream(i);
}
private int nextByte() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars == -1)
return -1; // end of file
}
return buf[curChar++];
}
public String next() {
int c;
do {
c = nextByte();
} while (c <= ' ');
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = nextByte();
} while (c > ' ');
return res.toString();
}
public String nextLine() {
int c;
do {
c = nextByte();
} while (c < '\n');
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = nextByte();
} while (c > '\n');
return res.toString().trim(); // .trim() used to remove '\n' from either ends
}
public int Int() {
int c;
do {
c = nextByte();
} while (c <= ' ');
int sgn = 1;
if (c == '-') {
sgn = -1;
c = nextByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = 10 * res + c - '0';
c = nextByte();
} while (c > ' ');
return res * sgn;
}
public long Long() {
int c;
do {
c = nextByte();
} while (c <= ' ');
int sgn = 1;
if (c == '-') {
sgn = -1;
c = nextByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = 10 * res + c - '0';
c = nextByte();
} while (c > ' ');
return res * sgn;
}
public double Double() {
return Double.parseDouble(next());
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | 585688fcc9028b126f65f98f6ff39cfc | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution {
private static final FastReader sc = new FastReader();
private static final int MOD = (int) (1e9) + 7;// ((a + b) % MOD + MOD) % MOD
public static void main(String[] args) throws IOException {
int t = sc.Int();
for (int i = 1; i <= t; ++i) {
// System.out.print("Case #" + i + ": ");
solve();
}
// solve();
sc.close();
}
public static void solve() throws IOException {
long n = sc.Long();
if(n == 1){
System.out.println(2);
return;
}
if(n % 3 == 0){
System.out.println(n / 3);
}
else if(n % 3 == 2){
System.out.println(n / 3 + 1);
}
else{
System.out.println((n - 4) / 3 + 2);
}
}
}
class FastReader {
private BufferedReader br;
private StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() throws IOException {
for (; st == null || !st.hasMoreTokens();) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int Int() throws IOException {
return Integer.parseInt(next());
}
public long Long() throws IOException {
return Long.parseLong(next());
}
public double Double() throws IOException {
return Double.parseDouble(next());
}
public float Float() throws IOException {
return Float.parseFloat(next());
}
public char Char() throws IOException {
return next().charAt(0);
}
public void close() throws IOException {
br.close();
}
}
class Pair<K, V> {
public K key;
public V value;
Pair(K k, V v) {
key = k;
value = v;
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | f44fd360e4ee669ad0112ccbf8068fae | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class FastI_O {
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st==null || !st.hasMoreTokens()){
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str="";
try {
str=br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException {
bw.append("" + object);
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
public static void main(String[] args) throws java.lang.Exception {
try {
FastReader in=new FastReader();
FastWriter out = new FastWriter();
long t=in.nextLong();
while(t-- > 0){
int n = in.nextInt();
if(n==1) {
System.out.println(2);
}
else if(n%3==0) {
System.out.println(n/3);
}
else if(n%3==2) {
System.out.println((n/3)+1);
}
else if(n%3==1) {
System.out.println(n/3+1);
}
}
out.close();
} catch (Exception e) {
return;
}
}
} | Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output | |
PASSED | fbbdbe57f6de4e18a75caebbe2b6bcf7 | train_109.jsonl | 1659623700 | You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public class Contest_1 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int []arr=new int[n];
int []count=new int[n];
for(int i=0;i<n;i++){
count[i]=0;
arr[i]=s.nextInt();
if(arr[i]==1){
count[i]=2;
}
else if(arr[i]%3==0){
count[i]=arr[i]/3;
}
else{
count[i] = arr[i] / 3 + 1;
}
}
for(int j=0;j<n;j++){
System.out.println(count[j]);
}
}
}
| Java | ["4\n\n1\n\n3\n\n4\n\n12"] | 1 second | ["2\n1\n2\n4"] | null | Java 17 | standard input | [
"greedy",
"math"
] | 208e285502bed3015b30ef10a351fd6d | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case. | 800 | For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.