QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#751274 | #9535. Arrow a Row | kindow# | AC ✓ | 23ms | 6752kb | C++20 | 2.3kb | 2024-11-15 17:50:57 | 2024-11-15 17:50:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
#define pb push_back
#define fi first
#define se second
int vis[maxn];
map<int,int>mp;
string s;
int n;
int work(int sta)
{
vis[sta-1] = 1;
int l = 0;
for(int i = sta; i <= n; ++i)
{
if(s[i] == '-')vis[i] = 1, l++;
else
{
break;
}
}
for(int i = sta + l; i <= sta + l + 2; ++i)
{
vis[i] = 1;
}
return l + 3;
}
void solve()
{
cin >> s;
n = s.size();
s = " " + s;
if(s[1] == '-')
{
cout << "No" << '\n';
return;
}
int flag = 0;
for(int i = 1; i <= n; ++i)
{
if(s[i] == '-')
{
flag = 1; break;
}
}
if(!flag)
{
cout << "No" << '\n';
return;
}
int cnt = 0;
for(int i = n; i > 0; --i)
{
if(s[i] == '>')cnt++;
else
{
break;
}
}
// cout << '\n' << cnt << '\n';
if(cnt < 3)
{
cout << "No" << '\n';
return;
}
for(int i = 1; i <= n; ++i) vis[i] = 0;
vector<int> pos;
for(int i = 1; i <= n; ++i)
{
if(s[i] == '-')
{
pos.pb(i);
int len = work(i);
// cout << "check1() : " << i << ' ' << len << '\n';
mp[i] = len - 3;
i += mp[i]-1;
// cout << "check() : " << i << ' ' << mp[i] << '\n';
}
}
vector<pair<int,int>> ans;
int cntx = 0;
for(int i = 1; i <= n; ++i)
{
if(!vis[i])
{
auto ret = upper_bound(pos.begin(), pos.end(), i) - pos.begin();
if(ret != pos.size())ans.pb({i, mp[pos[ret]] + 4});
else
{
cntx++;
}
}
}
// cout << cntx << '\n';
int las = n;
while(cntx && las)
{
if(cntx >= 3)
{
cntx -= 3;
ans.pb({las - 4, 5});
las -= 3;
}
else
{
cntx = 0;
ans.pb({las - 4, 5});
las -= 3;
}
}
for(int i = 1; i <= n; ++i)
{
if(s[i] == '-')
{
ans.pb({i-1, mp[i] + 4});
i += mp[i]-1;
}
}
cout << "Yes" << ' ' << ans.size() << '\n';
for(auto u : ans)
{
cout << u.fi << ' ' << u.se << '\n';
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// cout << "begin()" << '\n';
int t; cin >> t;
while(t--)solve();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3492kb
input:
4 >>->>> >>>-> >>>>> >->>>>>>
output:
Yes 2 1 5 2 5 No No Yes 2 4 5 1 5
result:
ok ok (4 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
126 >->-->>>> >--->->>>> >--->-->>> >>-->->>> >>-->>>>> >>->->>>> >>->>->>>> >-->->->>> >->->>>>>> >->>> >->->>>>> >>>->->>> >>->>>>>>> >>>>>->>> >->>>->>> >>--->->>> >>->>>> >->>>>->>> >>>>-->>> >---->>> >>>---->>> >>>>->>>> >->>-->>> >-->-->>>> >>---->>> >>--->>> >->>>-->>> >>-->>>> >>---->>>> >>-...
output:
Yes 3 5 5 1 5 3 6 Yes 3 6 5 1 7 5 5 Yes 2 1 7 5 6 Yes 3 1 6 2 6 5 5 Yes 3 1 6 5 5 2 6 Yes 4 1 5 5 5 2 5 4 5 Yes 4 1 5 6 5 2 5 5 5 Yes 3 1 6 4 5 6 5 Yes 3 6 5 1 5 3 5 Yes 1 1 5 Yes 3 5 5 1 5 3 5 Yes 4 1 5 2 5 3 5 5 5 Yes 4 1 5 6 5 3 5 2 5 Yes 5 1 5 2 5 3 5 4 5 5 5 Yes 2 1 5 5 5 Yes 3 1 7 2 7 6 5 Yes ...
result:
ok ok (126 test cases)
Test #3:
score: 0
Accepted
time: 4ms
memory: 3560kb
input:
4032 >>--->>>>>>>> >->>->->-->->>> >>--->>--->>> >>->->->>>>>>>> >->---->->>> >->>->>---->>>> >>>>>>>>->>>> >->>>--->>>->>> >->>->>-->>>>>> >->>-->---->>> >-->--->>>->>> >->---->>-->>>> >>------>>> >>>-->>--->>>>> >->->->>-->>>> >->->-->>->->>> >>->>>>-->->>>> >>>-->>->--->>> >->->>>>>->>>> >>-->->>...
output:
Yes 4 1 7 9 5 6 5 2 7 Yes 5 1 5 4 5 6 5 8 6 11 5 Yes 3 1 7 2 7 7 7 Yes 6 1 5 11 5 8 5 2 5 4 5 6 5 Yes 3 1 5 3 8 8 5 Yes 4 11 5 1 5 4 5 7 8 Yes 9 1 5 2 5 3 5 4 5 5 5 6 5 7 5 9 5 8 5 Yes 3 1 5 5 7 11 5 Yes 4 11 5 1 5 4 5 7 6 Yes 3 1 5 4 6 7 8 Yes 3 1 6 4 7 10 5 Yes 4 11 5 1 5 3 8 9 6 Yes 2 1 10 2 10 Y...
result:
ok ok (4032 test cases)
Test #4:
score: 0
Accepted
time: 9ms
memory: 3548kb
input:
10000 >>>>->->>->>->>>> >->-->>->>->>>>>> >->->>-->--->>>>> >---->-->->>>>>>> >->-->>--->>->>>> >->>->>>>>>-->>> >>--->->-->>->>> >-->---->>>->>> >->----->->->>>>> >>--->---->-->>>> >>-->->->--->>> >----->>-->>->>>> >-->->->>>>>->>>> >>->>---->-->>> >>->>-->>>-->>> >------>->>>->>>> >->->-->->>>->>>...
output:
Yes 8 1 5 2 5 3 5 13 5 4 5 6 5 9 5 12 5 Yes 5 13 5 1 5 3 6 7 5 10 5 Yes 5 13 5 1 5 3 5 6 6 9 7 Yes 5 13 5 10 5 1 8 6 6 9 5 Yes 5 13 5 1 5 3 6 7 7 12 5 Yes 5 9 6 10 6 1 5 4 5 11 6 Yes 5 1 7 2 7 6 5 8 6 12 5 Yes 3 1 6 4 8 11 5 Yes 5 13 5 1 5 3 9 9 5 11 5 Yes 5 1 7 13 5 2 7 6 8 11 6 Yes 5 1 6 2 6 5 5 7...
result:
ok ok (10000 test cases)
Test #5:
score: 0
Accepted
time: 19ms
memory: 3656kb
input:
10000 >>>-->>>>-->---->->->-->>> >>-->>>>->-->>->>> >->-->--->--->->-->>--->>->->>-->->->>>>>>->>>>----->->--->>----->>-->>>----->->->>>--->>->>-->->->->---->>->>>-->>->->>>->->>>>->>->->>-->>>->>->>-->>>>-->>-->>>->>->->>>--->>>-->>>--->>->->>>>>->->---->>>>->>> ->->>>>--->>>>>>->>>->>>>->->-->-->>...
output:
Yes 8 1 6 2 6 3 6 9 6 12 8 17 5 19 5 21 6 Yes 5 1 6 2 6 8 5 10 6 14 5 Yes 58 40 5 41 5 194 5 1 5 3 6 6 7 10 7 14 5 16 6 20 7 25 5 27 5 30 6 33 5 35 5 42 5 47 9 53 5 55 7 60 9 67 6 72 9 78 5 80 5 84 7 89 5 92 6 95 5 97 5 99 5 101 8 107 5 111 6 115 5 117 5 121 5 123 5 128 5 131 5 133 5 136 6 141 5 144...
result:
ok ok (10000 test cases)
Test #6:
score: 0
Accepted
time: 19ms
memory: 3528kb
input:
9999 ->->--->>>>->->--->>-- ->>>--->>>-->>--->>--- -->>>>>>>- >>>->>>>>>>-- >>-->-->->----->->>>>->>->---->-> >-->->>>--->->->>->->- >->--->--->>>>->>>----->------>>-->->>> >>->>>->>>---->>>->>>>>>>>>->--->>->>>>>-->>>->->->>-->->--->->-->->>->->->>-->-->>>>>>>>--->>--->->>>-->->----->>-->->>--->-->...
output:
No No No No No No Yes 8 1 5 3 7 7 7 14 5 18 9 24 10 32 6 35 5 Yes 43 1 5 22 5 23 5 24 5 25 5 26 5 39 6 85 7 86 7 87 7 88 7 2 5 6 5 10 8 17 5 27 5 29 7 34 5 40 6 45 5 47 5 49 5 52 6 55 5 57 7 61 5 63 6 66 5 69 5 71 5 73 5 76 6 79 6 89 7 94 7 98 5 102 6 105 5 107 9 114 6 117 5 120 7 124 6 Yes 27 92 5 ...
result:
ok ok (9999 test cases)
Test #7:
score: 0
Accepted
time: 23ms
memory: 6752kb
input:
5 >-->>>>>--->->->>->>>>>->->-->-->->>>-->->--->>>------>->>-->>>------->>---->-->>>>>>-->>--->>-->->->>>>->-->------>>->>>>->>>-->---->--->>-->-->->--->->->->->>->-->->--->>>>->>->--->->>-->>>>>>->>>>->>--->->>-->>->->---->>>->->>->>->--->->->-->->>->->-->->------>>>->>>>>->>-->>->>>->>>>>----->---...
output:
No No Yes 27013 1 5 2 5 63 5 126 5 127 5 192 5 212 7 381 6 382 6 451 6 468 5 469 5 470 5 509 6 510 6 511 6 512 6 513 6 514 6 536 5 559 6 560 6 628 5 644 5 645 5 646 5 700 6 701 6 702 6 703 6 704 6 937 5 938 5 939 5 940 5 941 5 942 5 943 5 949 13 950 13 974 6 975 6 1075 7 1076 7 1093 8 1178 6 1179 6 ...
result:
ok ok (5 test cases)
Test #8:
score: 0
Accepted
time: 13ms
memory: 5580kb
input:
5 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>...
output:
No Yes 99996 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 5 26 5 27 5 28 5 29 5 30 5 31 5 32 5 33 5 34 5 35 5 36 5 37 5 38 5 39 5 40 5 41 5 42 5 43 5 44 5 45 5 46 5 47 5 48 5 49 5 50 5 51 5 52 5 53 5 54 5 55 5 56 5 57 5 58 5 59 5 6...
result:
ok ok (5 test cases)
Test #9:
score: 0
Accepted
time: 15ms
memory: 4008kb
input:
20 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>...
output:
Yes 20993 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 5 26 5 27 5 28 5 29 5 30 5 31 5 32 5 33 5 34 5 35 5 36 5 37 5 38 5 39 5 40 5 41 5 42 5 43 5 44 5 45 5 46 5 47 5 48 5 49 5 50 5 51 5 52 5 53 5 54 5 55 5 56 5 57 5 58 5 59 5 60 5...
result:
ok ok (20 test cases)
Test #10:
score: 0
Accepted
time: 14ms
memory: 3920kb
input:
20 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>...
output:
Yes 9851 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 5 26 5 27 5 28 5 29 5 30 5 31 5 32 5 33 5 34 5 35 5 36 5 37 5 38 5 39 5 40 5 41 5 42 5 43 5 44 5 45 5 46 5 47 5 48 5 49 5 50 5 51 5 52 5 53 5 54 5 55 5 56 5 57 5 58 5 59 5 60 5 ...
result:
ok ok (20 test cases)
Extra Test:
score: 0
Extra Test Passed