UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#207142#3733. 切数游戏Soulmate100105ms1552kbC++11717b2024-07-27 17:56:352024-07-27 20:03:32

answer

#include <bits/stdc++.h>

using namespace std;
int a[1000005];
int f(int n) 
{
    long long s=0;
    for (int num:a) 
    {
        s+=num;
    }
    
    if (s%3!=0) 
    {
        return 0;
    }
    
    long long ps=s/3;
    long long t=2*ps;
    
    long long c=0;
    int k=0;
    int p=0;
    
    for (int i=0;i<n-1;++i) 
    {
        c+=a[i];
        
        if (c==t) 
        {
            p+=k;
        }
        
        if (c==ps) 
        {
            k++;
        }
    }
    
    return p;
}
int main() 
{
    
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    
    cout<<f(n)<<endl;
    
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 2ms
memory: 1200kb

input:

486
0 -7035 -3680 -8556 -2590 2202 1857 707 6059 -6910 6232 -474 -5627 9197 -7210 -373 5757 -8063 -1...

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: 10
Accepted
time: 0ms
memory: 1196kb

input:

540
0 -9304 7419 1885 0 0 -4189 4189 0 -5574 -63 2547 3090 -5671 1678 3993 -1943 1943 -3720 3720 -73...

output:

16

result:

ok 1 number(s): "16"

Test #3:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

990
-6697 -298 -5157 -6137 1763 5159 -4902 7561 -6985 5504 -7844 -1671 -5404 -3509 -971 6878 -9921 4...

output:

20

result:

ok 1 number(s): "20"

Test #4:

score: 10
Accepted
time: 2ms
memory: 1196kb

input:

630
0 -7062 -6055 2567 -6899 -599 9773 -8779 576 -9134 3776 -3934 -1074 4865 3939 -5259 -4047 -2572 ...

output:

32

result:

ok 1 number(s): "32"

Test #5:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

792
-2222 -2246 -3382 1589 -3578 6591 -2788 -4561 -6833 -4695 -2470 3695 -45 -6683 -9801 -4794 -2788...

output:

40

result:

ok 1 number(s): "40"

Test #6:

score: 10
Accepted
time: 21ms
memory: 1488kb

input:

73962
-8321 3501 1816 3004 -1996 316 -4750 -7105 6173 -7364 -5192 6625 5770 7523 -5256 -7558 9528 32...

output:

4503

result:

ok 1 number(s): "4503"

Test #7:

score: 10
Accepted
time: 17ms
memory: 1412kb

input:

55620
0 -4501 4501 -2321 2321 0 -4073 4073 -1088 -1771 2859 -16 -325 341 0 -6666 4763 1903 0 0 0 0 0...

output:

115

result:

ok 1 number(s): "115"

Test #8:

score: 10
Accepted
time: 19ms
memory: 1456kb

input:

65970
-5847 -144 81 -2599 -307 6587 -4046 1206 2165 -424 -1174 4502 -7115 -6564 6954 3264 -8717 4248...

output:

3024

result:

ok 1 number(s): "3024"

Test #9:

score: 10
Accepted
time: 18ms
memory: 1420kb

input:

56610
0 0 0 0 0 -7041 -7721 -5889 -3636 5526 -9355 5573 -7402 -8503 -3252 -6336 -2090 1968 -2272 -37...

output:

2072

result:

ok 1 number(s): "2072"

Test #10:

score: 10
Accepted
time: 26ms
memory: 1552kb

input:

91782
-8103 -776 -4315 -4322 -751 -4423 -1397 9170 -6972 5484 -9303 5869 2194 -5814 -4022 7005 9963 ...

output:

8463

result:

ok 1 number(s): "8463"