#24397: RE了 But why?


s0975247623@gmail.com (愛吃又愛睡的Weber)

學校 : 高雄市立高雄高級中學
編號 : 136210
來源 : [42.77.23.117]
最後登入時間 :
2023-01-17 20:53:17
f313. 2. 人口遷移 -- 2020年10月APCS | From: [223.139.137.226] | 發表日期 : 2021-02-13 20:06

前50%測資RE

後50%AC

測資比較大的反而通過?

所以是題目設定的問題嗎

(程式碼將近兩百行,有耐心就看ㄅ

#include <iostream>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r,c,k1,m;
    cin>>r>>c>>k1>>m;
    int arr[r][c]={},arr1[r][c]={};
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++) cin>>arr[i][j];
    }
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<r;j++)
        {
            for(int k=0;k<c;k++)
            {
                arr1[j][k]=arr[j][k];
            }
        }
        for(int j=0;j<r;j++)
        {
            for(int k=0;k<c;k++)
            {
                if(arr1[j][k]==-1) continue;
                else if(j==0)
                {
                    if(k==0)
                    {
                        if(arr1[j][k+1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k+1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j+1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j+1][k]+=arr1[j][k]/k1;
                        }
                    }
                    else if(k==c-1)
                    {
                        if(arr1[j][k-1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k-1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j+1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j+1][k]+=arr1[j][k]/k1;
                        }
                    }
                    else
                    {
                        if(arr1[j][k-1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k-1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j+1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j+1][k]+=arr1[j][k]/k1;
                        }
                        if(arr1[j][k+1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k+1]+=arr1[j][k]/k1;
                        }
                    }
                }
                else if(j==r-1)
                {
                    if(k==0)
                    {
                        if(arr1[j][k+1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k+1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j-1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j-1][k]+=arr1[j][k]/k1;
                        }
                    }
                    else if(k==c-1)
                    {
                        if(arr1[j][k-1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k-1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j-1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j-1][k]+=arr1[j][k]/k1;
                        }
                    }
                    else
                    {
                        if(arr1[j][k-1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k-1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j-1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j-1][k]+=arr1[j][k]/k1;
                        }
                        if(arr1[j][k+1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k+1]+=arr1[j][k]/k1;
                        }
                    }
                }
                else//
                {
                    if(k==0)
                    {
                        if(arr1[j][k+1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k+1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j-1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j-1][k]+=arr1[j][k]/k1;
                        }
                        if(arr1[j+1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j+1][k]+=arr1[j][k]/k1;
                        }
                    }
                    else if(k==c-1)
                    {
                        if(arr1[j][k-1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k-1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j-1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j-1][k]+=arr1[j][k]/k1;
                        }
                        if(arr1[j+1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j+1][k]+=arr1[j][k]/k1;
                        }
                    }
                    else
                    {
                        if(arr1[j][k-1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k-1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j-1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j-1][k]+=arr1[j][k]/k1;
                        }
                        if(arr1[j][k+1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k+1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j+1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j+1][k]+=arr1[j][k]/k1;
                        }
                    }
                }
            }
        }
    }
    int min=1000000,max=0;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            if(arr[i][j]==-1) continue;
            if(arr[i][j]>max) max=arr[i][j];
            if(arr[i][j]<min) min=arr[i][j];
        }
    }
    cout<<min<<'\n'<<max<<'\n';
}

麻煩電神幫忙

 
#27903: Re:RE了 But why?


htt10501871050187@gmail.com (tony123 huang)

學校 : 不指定學校
編號 : 119179
來源 : [61.70.171.129]
最後登入時間 :
2023-06-05 02:52:21
f313. 2. 人口遷移 -- 2020年10月APCS | From: [218.173.176.74] | 發表日期 : 2021-11-04 22:51

前50%測資RE

後50%AC

測資比較大的反而通過?

所以是題目設定的問題嗎

(程式碼將近兩百行,有耐心就看ㄅ

#include
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r,c,k1,m;
    cin>>r>>c>>k1>>m;
    int arr[r][c]={},arr1[r][c]={};
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++) cin>>arr[i][j];
    }
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<r;j++)
        {
            for(int k=0;k<c;k++)
            {
                arr1[j][k]=arr[j][k];
            }
        }
        for(int j=0;j<r;j++)
        {
            for(int k=0;k<c;k++)
            {
                if(arr1[j][k]==-1) continue;
                else if(j==0)
                {
                    if(k==0)
                    {
                        if(arr1[j][k+1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k+1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j+1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j+1][k]+=arr1[j][k]/k1;
                        }
                    }
                    else if(k==c-1)
                    {
                        if(arr1[j][k-1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k-1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j+1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j+1][k]+=arr1[j][k]/k1;
                        }
                    }
                    else
                    {
                        if(arr1[j][k-1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k-1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j+1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j+1][k]+=arr1[j][k]/k1;
                        }
                        if(arr1[j][k+1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k+1]+=arr1[j][k]/k1;
                        }
                    }
                }
                else if(j==r-1)
                {
                    if(k==0)
                    {
                        if(arr1[j][k+1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k+1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j-1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j-1][k]+=arr1[j][k]/k1;
                        }
                    }
                    else if(k==c-1)
                    {
                        if(arr1[j][k-1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k-1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j-1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j-1][k]+=arr1[j][k]/k1;
                        }
                    }
                    else
                    {
                        if(arr1[j][k-1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k-1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j-1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j-1][k]+=arr1[j][k]/k1;
                        }
                        if(arr1[j][k+1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k+1]+=arr1[j][k]/k1;
                        }
                    }
                }
                else//
                {
                    if(k==0)
                    {
                        if(arr1[j][k+1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k+1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j-1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j-1][k]+=arr1[j][k]/k1;
                        }
                        if(arr1[j+1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j+1][k]+=arr1[j][k]/k1;
                        }
                    }
                    else if(k==c-1)
                    {
                        if(arr1[j][k-1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k-1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j-1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j-1][k]+=arr1[j][k]/k1;
                        }
                        if(arr1[j+1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j+1][k]+=arr1[j][k]/k1;
                        }
                    }
                    else
                    {
                        if(arr1[j][k-1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k-1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j-1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j-1][k]+=arr1[j][k]/k1;
                        }
                        if(arr1[j][k+1]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j][k+1]+=arr1[j][k]/k1;
                        }
                        if(arr1[j+1][k]!=-1)
                        {
                            arr[j][k]-=arr1[j][k]/k1;
                            arr[j+1][k]+=arr1[j][k]/k1;
                        }
                    }
                }
            }
        }
    }
    int min=1000000,max=0;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            if(arr[i][j]==-1) continue;
            if(arr[i][j]>max) max=arr[i][j];
            if(arr[i][j]<min) min=arr[i][j];
        }
    }
    cout<<min<<'\n'<<max<<'\n';
}

麻煩電神幫忙

1. 在確定位置之後沒有判斷是否有下一列就進行計算,會導致超出陣列範圍,應為re原因。

2. 前半跟後半的主要差異通常是一維跟二維,並非僅資料量而已,這也解釋了為何你的code在前半測資re後半卻全過的問題。

 
ZeroJudge Forum