QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#563933#7757. Palm IslandpotentialTL 1ms7756kbC++201.7kb2024-09-14 17:28:312024-09-14 17:28:33

Judging History

你现在查看的是最新测评结果

  • [2024-09-14 17:28:33]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7756kb
  • [2024-09-14 17:28:31]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
# define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
# define int long long
# define lowbit(x) (x & (-x))
# define fi first
# define se second
// # define endl '\n'

inline int Read();

typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const int N = 1e6 + 10;

map <int, int> mp;
vector <int> v;

int a[N], pre[N], b[N];
string ans = "";
void Solve(){
    int n;
    cin >> n;
    ans = "";
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i ++){
        cin >> b[i];
        pre[b[i]] = b[i - 1];
    }
    pre[b[1]] = b[n];
    int k = 1;
    while(k){
        // for(int i = 1; i <= n; i ++){
        //     cout << a[i] <<" \n"[i == n];
        // }
        // cout <<"\n";
        int x = 2, y = n;
        while(a[1] != pre[a[x]]){
            a[++ y] = a[x];
            a[x ++] = 0;
            ans += '2';
        }
        int f = 0;
        for(int i = x; i <= y; i ++){
            if(a[i] != b[i - x + 2]){
                f = 1;
                break;
            }
        }
        for(int i = 2; i <= n; i ++){
            a[i] = a[i + x - 2];
        }
        if(f == 0) break;
        a[n + 1] = a[1];
        for(int i = 1; i <= n; i ++){
            a[i] = a[i + 1];
        }
        ans += "1";
    }
    cout << ans <<"\n";


}
signed main(){
    IOS;
    int T = 1;
    cin >> T;
    while (T--) 
        Solve();
    return 0;
}
inline int Read(){
    int x = 0, f = 1; char c = getchar();
    while (c < '0' || c > '9'){ if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7756kb

input:

2
3
1 2 3
2 3 1
4
1 2 3 4
2 1 3 4

output:

1
2111

result:

ok Correct. (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

200
3
3 1 2
2 3 1
4
2 4 1 3
2 1 4 3
4
1 4 2 3
2 1 3 4
5
4 3 2 1 5
2 4 5 3 1
5
2 1 5 4 3
5 2 4 1 3
4
4 3 1 2
1 2 4 3
3
1 2 3
3 1 2
4
1 4 2 3
2 1 4 3
4
1 3 2 4
1 4 3 2
3
3 2 1
1 3 2
3
2 3 1
1 3 2
4
1 4 3 2
3 1 2 4
3
1 2 3
1 3 2
3
3 2 1
2 3 1
5
5 1 3 2 4
2 4 5 1 3
4
4 3 1 2
1 4 3 2
4
1 3 4 2
2 4 3 1
3
...

output:


result: