Advertisement
YEZAELP

PROG-1088 : กิ้งก่า (iguana)

Jun 23rd, 2020 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. using pii = pair <int, int>;
  6.  
  7. int red, green, blue;
  8. void cal(int val, int l){
  9.     if(val % 3 == 1) red += l;
  10.     else if(val % 3 == 2) green += l;
  11.     else blue += l;
  12. }
  13.  
  14. int main(){
  15.  
  16.     int n, m;
  17.     scanf("%d%d", &n, &m);
  18.  
  19.     pii S[2*m + 1];
  20.  
  21.     for(int i=1;i<=m;i++){
  22.         int a, b;
  23.         scanf("%d%d", &a, &b);
  24.         S[2*i - 1].first = a;
  25.         S[2*i - 1].second = 1;
  26.         S[2*i].first = b+1;
  27.         S[2*i].second = 2;
  28.     }
  29.  
  30.     char a;
  31.     scanf(" %c", &a);
  32.  
  33.     sort(S + 1, S + 2*m + 1);
  34.  
  35.     int s = 1, val = 1;
  36.     for(int i=1;i<=2*m;i++){
  37.         int idx = S[i].first, opr = S[i].second;
  38.         cal(val % 3, idx - s);
  39.         s = idx;
  40.         if(opr == 1) val ++;
  41.         else val --;
  42.     }
  43.     cal(val, n + 1 - s);
  44.  
  45.     int sum;
  46.     if(a == 'R') sum = (green * 2) + blue;
  47.     else if(a == 'G') sum = red + (blue * 2);
  48.     else sum = (red * 2) + green;
  49.     printf("%d", sum);
  50.  
  51.     return 0;
  52. }
  53. /*
  54. 6 1
  55. 3 3
  56. G
  57.  
  58. 10 7
  59. 1 3
  60. 2 8
  61. 6 9
  62. 3 5
  63. 6 9
  64. 1 5
  65. 2 8
  66. R
  67.  
  68. 10 4
  69. 1 3
  70. 3 5
  71. 5 7
  72. 7 9
  73. R
  74.  
  75. 10 4
  76. 1 4
  77. 3 4
  78. 2 6
  79. 4 8
  80. G
  81.  
  82. 10 5
  83. 1 10
  84. 3 5
  85. 6 9
  86. 1 6
  87. 3 9
  88. B
  89.  
  90. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement