QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425313 | #6537. One, Two, Three | crsfaa | WA | 1ms | 3920kb | C++14 | 2.4kb | 2024-05-30 08:25:27 | 2024-05-30 08:25:28 |
Judging History
answer
#include<bits/stdc++.h>
#define Yukinoshita namespace
#define Yukino std
using Yukinoshita Yukino;
int read()
{
int s=0;
char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s;
}
using vec=vector<int>;
stack<vec> A,C,AB,CB;
stack<vec> ABC,ACB,ABCB;
//CBAB A
//CBA AB
vec get(stack<vec> &a)
{
vec res=a.top();
a.pop();
return res;
}
vec operator +(vec x,vec y)
{
for(auto i:y) x.push_back(i);
return x;
}
const int mxn=6e6+5;
char s[mxn];
/*
CABBCA
6
3 1 2 2 3 1
6
1 2 3 2 1 3
*/
int main()
{
int n=read(),i;
for(i=0;i<n;i++)
{
int x=read()+'A'-1;
s[i]=x;
if(x=='A')
{
if(CB.size())
ABC.push(get(CB)+vec{i});
else if(ABCB.size())
{
vec tp=get(ABCB);
if(s[tp[0]]==x)
AB.push({tp[0],tp[1]}),
ABC.push({tp[2],tp[3],i});
else
AB.push({tp[2],tp[3]}),
ABC.push({tp[0],tp[1],i});
}
else if(ACB.size())
{
vec tp=get(ACB);
if(s[tp[0]]==x)
ABC.push({tp[1],tp[2],i}),
A.push({tp[0]});
else
ABC.push({tp[0],tp[2],i}),
A.push({tp[1]});
}
else A.push({i});
}
if(x=='B')
{
if(ACB.size())
{
vec tp=get(ACB);
if(s[tp[0]]=='A')
AB.push({tp[0],i}),
CB.push({tp[1],tp[2]});
else
CB.push({tp[0],i}),
AB.push({tp[1],tp[2]});
}
else if(A.size()&&C.size())
{
vec ta=get(A),tb=get(C);
ACB.push({min(ta[0],tb[0]),max(ta[0],tb[0]),i});
}
else if(A.size())
AB.push(get(A)+vec{i});
else if(C.size())
CB.push(get(C)+vec{i});
else if(ABC.size())
ABCB.push(get(ABC)+vec{i});
}
if(x=='C')
{
if(AB.size())
ABC.push(get(AB)+vec{i});
else if(ABCB.size())
{
vec tp=get(ABCB);
if(s[tp[0]]==x)
CB.push({tp[0],tp[1]}),
ABC.push({tp[2],tp[3],i});
else
CB.push({tp[2],tp[3]}),
ABC.push({tp[0],tp[1],i});
}
else if(ACB.size())
{
vec tp=get(ACB);
if(s[tp[0]]==x)
ABC.push({tp[1],tp[2],i}),
C.push({tp[0]});
else
ABC.push({tp[0],tp[2],i}),
C.push({tp[1]});
}
else C.push({i});
}
}
printf("%d\n",ABC.size()+ABCB.size());
for(;ABC.size();ABC.pop())
printf("%d %d %d\n",ABC.top()[0],ABC.top()[1],ABC.top()[2]);
for(;ABCB.size();ABCB.pop())
printf("%d %d %d\n",ABCB.top()[0],ABCB.top()[1],ABCB.top()[2]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3756kb
input:
6 3 1 2 2 3 1
output:
2 0 3 5 1 2 4
result:
ok count=2
Test #2:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
6 2 1 3 1 3 2
output:
0
result:
ok count=0
Test #3:
score: 0
Accepted
time: 1ms
memory: 3920kb
input:
3000 1 1 1 1 1 3 1 1 3 3 1 3 1 1 2 3 1 1 2 1 2 1 3 3 3 1 1 2 1 2 2 3 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 3 3 1 1 2 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 2 3 1 1 1 1 3 3 2 1 3 1 1 2 3 1 2 3 1 1 1 2 1 1 1 1 2 3 2 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 3 1 3 3 1 1 1 1 3 1 1 2 1 1 1 3 3 1 1 1 1 2 1 1 1 1 1 2 3 3 1...
output:
499 2996 2997 2999 2956 2992 2993 2983 2984 2985 2978 2980 2981 2968 2969 2970 2963 2965 2966 2960 2961 2962 2755 2758 2951 2760 2761 2940 2759 2762 2934 2765 2766 2931 2926 2928 2930 2855 2856 2927 2871 2872 2921 2873 2874 2919 2911 2912 2913 2885 2886 2909 2898 2900 2908 2884 2887 2899 2880 2881 2...
result:
ok count=499
Test #4:
score: 0
Accepted
time: 1ms
memory: 3860kb
input:
3000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
1 1932 1933 2901
result:
ok count=1
Test #5:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
3000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...
output:
1 1755 1756 2819
result:
ok count=1
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3768kb
input:
1500 1 1 1 2 1 1 1 2 2 2 2 2 1 1 3 1 2 2 3 1 2 2 2 2 1 2 1 2 1 1 3 1 2 2 2 2 1 1 3 1 1 2 2 3 2 1 3 1 1 2 2 2 1 2 2 2 2 2 1 2 3 2 3 2 3 2 1 3 2 1 2 3 2 2 3 2 3 1 1 3 1 3 1 3 3 3 1 3 3 3 1 1 3 1 3 1 3 1 1 1 3 1 3 1 3 3 1 1 1 3 1 1 3 1 1 1 1 1 3 3 3 3 1 3 1 1 1 1 3 3 3 3 3 3 1 3 1 1 1 3 1 3 1 1 1 1 3 1...
output:
494 223 1222 1499 559 621 1498 221 1224 1497 220 1226 1496 336 1102 1495 335 1104 1494 219 1228 1493 218 1230 1492 217 1232 1491 216 1234 1490 215 1236 1489 317 1138 1488 212 1238 1487 283 1210 1486 282 1213 1485 207 1240 1484 281 1215 1483 280 1217 1482 279 1219 1481 206 1242 1480 275 1221 1479 205...
result:
wrong answer the number of matches is different