#P7877. 「SWTR-7」Spider Solitaire
「SWTR-7」Spider Solitaire
Description
Given an initial Spider Solitaire position, Little A wants to know whether it is possible to win. If yes, output and the minimum number of moves needed to win. Otherwise output .
Little A also wants to know, for each card , the minimum number of moves needed to move , including the move that moves itself. If it is impossible to move it, output -1.
“Simplified statement”
There are horizontal piles of numbers, containing a total of numbers. Each pile has or more numbers. Across all piles are exactly all numbers from to .
You may take some consecutive numbers on the right end of a pile that are strictly decreasing with common difference , and move them in the original order to the right end of another non-empty pile, if and only if the rightmost number of that non-empty pile is a number .
Find the minimum number of moves to move all numbers into a single pile such that they are decreasing from left to right. If there is no solution, output .
In addition, for each number , you must output the minimum number of moves needed to move .
Input Format
The first line contains an integer , the subtask id.
The second line contains two integers , representing the number of cards in the deck and the number of piles.
Then follow lines. Each line starts with an integer for the number of cards in that pile, followed by integers describing the pile from left to right.
Output Format
If you can win, output on the first line and the minimum number of moves on the second line. Otherwise output one line .
Whether you can win or not, you also need to output lines. The -th line contains an integer between and , indicating the minimum number of moves needed to move .
0
9 3
6 9 8 4 3 2 1
2 7 5
1 6
YES
4
1
1
1
1
1
2
3
-1
-1
0
13 4
4 13 10 1 7
3 11 4 8
4 6 5 3 2
2 12 9
YES
10
2
2
2
3
3
3
1
1
3
6
7
8
-1
0
5 1
5 5 4 3 2 1
YES
0
-1
-1
-1
-1
-1
0
17 10
2 12 14
1 3
3 1 13 15
0
2 9 8
1 5
3 16 7 6
2 11 2
1 4
2 17 10
YES
14
4
1
1
1
1
1
1
1
1
2
3
4
3
1
2
4
-1
0
13 4
4 10 1 13 7
4 11 12 4 8
4 6 5 3 2
1 9
NO
-1
2
2
3
3
3
1
1
-1
-1
6
5
-1
Hint
“Sample 1 Explanation”
Since 1,2,3,4,5 can be moved directly, it takes at least 1 move to move them.
Since you need to move 5 to the right of 6 before 6 can be moved, it takes at least 2 moves to move 6.
Since you need to first move 5 to the right of 6, then move 4,3,2,1 to the right of 5 before 7 can be moved, it takes at least 3 moves to move 7.
Clearly, 8,9 cannot be moved.
“Special Judge”
This problem uses Special Judge. Please strictly follow the output format:
- If you correctly output whether you can win, and if you can win, you correctly output the minimum number of moves, you will get at least of the score for this test.
- Based on the previous part, if you correctly output the minimum number of moves for each card, you will get the remaining of the score for this test. That is, if your output is wrong in the previous part, you will not get any score for this part either.
- If your output format is wrong, you will get for this test, including but not limited to only outputting whether you can win.
- Note in particular that if you cannot correctly compute the minimum number of moves for each card, please randomly output any integers in , otherwise you will get for this test.
- You must output a newline at the end of every line, including the last line.
The checker is given at the end of the problem.
“Constraints and Notes”
This problem uses bundled testdata.
- Subtask #0 (0 points): the samples.
- Subtask #1 (15 points): , .
- Subtask #2 (15 points): , .
- Subtask #3 (25 points): , .
- Subtask #4 (30 points): .
- Subtask #5 (15 points): no special restrictions.
For of the testdata, . Time limit: 1s. Memory limit: 512MB.
“Source”
Sweet Round 07 D.
idea & solution & data: Alex_Wei; validation: chenxia25.
Below is the checker. You need testlib.h to compile successfully.
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb emplace_back
#define mp make_pair
#define vint vector <int>
#define vpii vector <pii>
#define all(x) x.begin(),x.end()
#define sor(x) sort(all(x))
#define rev(x) reverse(all(x))
#define mem(x,v) memset(x,v,sizeof(x))
#define rint inf.readInt
#define reof inf.readEof()
#define reoln inf.readEoln()
#define rspace inf.readSpace()
// wrong answer : quitf(_wa,"The answer is wrong")
// accepted : quitf(_ok,"The answer is correct")
// partly correct : quitp(0.5,"The answer is partly correct")
int main(int argc,char* argv[]){
registerTestlibCmd(argc,argv);
string jans=ans.readToken();
string pans=ouf.readToken(jans);
int sub=rint(),n=rint(),diff=0;
if(jans=="YES"){
int jstep=ans.readInt();
int pstep=ouf.readInt();
if(jstep!=pstep)quitf(_wa,"The answer is wrong");
}
for(int i=1;i<=n;i++){
int jans=ans.readInt();
int pans=ouf.readInt();
if(jans!=pans)diff=1;
}
while(!ouf.seekEof())ouf.readToken();
while(!inf.seekEof())inf.readToken();
while(!ans.seekEof())ans.readToken();
if(diff)quitp(0.4,"The answer is partially correct");
else quitf(_ok,"OK, you AK IOI");
return 0;
}
Translated by ChatGPT 5
京公网安备 11011102002149号