• Codeforces Round #353 (Div. 2)Restoring Painting


    Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.

    • The painting is a square 3 × 3, each cell contains a single integer from 1 to n, and different cells may contain either different or equal integers.
    • The sum of integers in each of four squares 2 × 2 is equal to the sum of integers in the top left square 2 × 2.
    • Four elements abc and d are known and are located as shown on the picture below.

    Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.

    Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.

    Input

    The first line of the input contains five integers nabc and d (1 ≤ n ≤ 100 000, 1 ≤ a, b, c, d ≤ n) — maximum possible value of an integer in the cell and four integers that Vasya remembers.

    Output

    Print one integer — the number of distinct valid squares.

    Examples
    input
    2 1 1 1 2
    output
    2
    input
    3 3 1 2 3
    output
    6
    Note

    Below are all the possible paintings for the first sample.

    In the second sample, only paintings displayed below satisfy all the rules.

    注意数据范围:

    #include<iostream>
    using namespace std;
    typedef long long ll;
    int main()
    {
        ll n,a,b,c,d,s=0;
        cin>>n>>a>>b>>c>>d;
        
        for(int i=1;i<=n;i++)
        {
            ll q1,q2,q3,q4,q5;
            q1=i;
            q2=q1+b-c;
            q4=q1+a-d;
            q5=q4+b-c;
            int cnt=0;
            if(q1>=1&&q1<=n)cnt++;
            if(q2>=1&&q2<=n)cnt++;
            if(q4>=1&&q4<=n)cnt++;
            if(q5>=1&&q5<=n)cnt++;
                if(cnt==4)
            s++;
        }
            cout<<s*n;
    }
  • 相关阅读:
    20145334赵文豪 《信息安全系统设计基础》第2周学习总结
    20145334赵文豪《信息安全系统设计基础》第1周学习总结
    关于第五周大家学习问题的总结
    20145334 第五次 java 实验报告
    20145334 《Java程序设计》第10周学习总结
    实验四 Android开发基础
    # 20145334 《Java程序设计》第9周学习总结
    20145334实验三《敏捷开发与XP实践》
    实验二:面向对象设计
    程序的机器级表示内容补充及扩展
  • 原文地址:https://www.cnblogs.com/wangmenghan/p/5518567.html
Copyright © 2020-2023  润新知